Skip to content

Commit f3480c3

Browse files
committed
[Community Pipeline] Skip Marigold depth_colored generation by passing color_map=None
1 parent 534f5d5 commit f3480c3

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

examples/community/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pipeline_output = pipe(
105105
# processing_res=768, # (optional) Maximum resolution of processing. If set to 0: will not resize at all. Defaults to 768.
106106
# match_input_res=True, # (optional) Resize depth prediction to match input resolution.
107107
# batch_size=0, # (optional) Inference batch size, no bigger than `num_ensemble`. If set to 0, the script will automatically decide the proper batch size. Defaults to 0.
108-
# color_map="Spectral", # (optional) Colormap used to colorize the depth map. Defaults to "Spectral".
108+
# color_map="Spectral", # (optional) Colormap used to colorize the depth map. Defaults to "Spectral". Set to `None` to skip colormap generation.
109109
# show_progress_bar=True, # (optional) If true, will show progress bars of the inference progress.
110110
)
111111

examples/community/marigold_depth_estimation.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ class MarigoldDepthOutput(BaseOutput):
5050
Args:
5151
depth_np (`np.ndarray`):
5252
Predicted depth map, with depth values in the range of [0, 1].
53-
depth_colored (`PIL.Image.Image`):
53+
depth_colored (`None` or `PIL.Image.Image`):
5454
Colorized depth map, with the shape of [3, H, W] and values in [0, 1].
5555
uncertainty (`None` or `np.ndarray`):
5656
Uncalibrated uncertainty(MAD, median absolute deviation) coming from ensembling.
5757
"""
5858

5959
depth_np: np.ndarray
60-
depth_colored: Image.Image
60+
depth_colored: Union[None, Image.Image]
6161
uncertainty: Union[None, np.ndarray]
6262

6363

@@ -139,14 +139,15 @@ def __call__(
139139
If set to 0, the script will automatically decide the proper batch size.
140140
show_progress_bar (`bool`, *optional*, defaults to `True`):
141141
Display a progress bar of diffusion denoising.
142-
color_map (`str`, *optional*, defaults to `"Spectral"`):
142+
color_map (`str`, *optional*, defaults to `"Spectral"`, pass `None` to skip colorized depth map generation):
143143
Colormap used to colorize the depth map.
144144
ensemble_kwargs (`dict`, *optional*, defaults to `None`):
145145
Arguments for detailed ensembling settings.
146146
Returns:
147147
`MarigoldDepthOutput`: Output class for Marigold monocular depth prediction pipeline, including:
148148
- **depth_np** (`np.ndarray`) Predicted depth map, with depth values in the range of [0, 1]
149-
- **depth_colored** (`PIL.Image.Image`) Colorized depth map, with the shape of [3, H, W] and values in [0, 1]
149+
- **depth_colored** (`None` or `PIL.Image.Image`) Colorized depth map, with the shape of [3, H, W] and
150+
values in [0, 1]. None if `color_map` is `None`
150151
- **uncertainty** (`None` or `np.ndarray`) Uncalibrated uncertainty(MAD, median absolute deviation)
151152
coming from ensembling. None if `ensemble_size = 1`
152153
"""
@@ -233,12 +234,15 @@ def __call__(
233234
depth_pred = depth_pred.clip(0, 1)
234235

235236
# Colorize
236-
depth_colored = self.colorize_depth_maps(
237-
depth_pred, 0, 1, cmap=color_map
238-
).squeeze() # [3, H, W], value in (0, 1)
239-
depth_colored = (depth_colored * 255).astype(np.uint8)
240-
depth_colored_hwc = self.chw2hwc(depth_colored)
241-
depth_colored_img = Image.fromarray(depth_colored_hwc)
237+
if color_map is not None:
238+
depth_colored = self.colorize_depth_maps(
239+
depth_pred, 0, 1, cmap=color_map
240+
).squeeze() # [3, H, W], value in (0, 1)
241+
depth_colored = (depth_colored * 255).astype(np.uint8)
242+
depth_colored_hwc = self.chw2hwc(depth_colored)
243+
depth_colored_img = Image.fromarray(depth_colored_hwc)
244+
else:
245+
depth_colored_img = None
242246
return MarigoldDepthOutput(
243247
depth_np=depth_pred,
244248
depth_colored=depth_colored_img,

0 commit comments

Comments
 (0)