Unverified Commit e5ee05da authored by qqii's avatar qqii Committed by GitHub
Browse files

[Community Pipeline] Skip Marigold `depth_colored` with `color_map=None` (#7170)

[Community Pipeline] Skip Marigold depth_colored generation by passing color_map=None
parent e6ff7528
...@@ -105,7 +105,7 @@ pipeline_output = pipe( ...@@ -105,7 +105,7 @@ pipeline_output = pipe(
# processing_res=768, # (optional) Maximum resolution of processing. If set to 0: will not resize at all. Defaults to 768. # processing_res=768, # (optional) Maximum resolution of processing. If set to 0: will not resize at all. Defaults to 768.
# match_input_res=True, # (optional) Resize depth prediction to match input resolution. # match_input_res=True, # (optional) Resize depth prediction to match input resolution.
# 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. # 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.
# color_map="Spectral", # (optional) Colormap used to colorize the depth map. Defaults to "Spectral". # color_map="Spectral", # (optional) Colormap used to colorize the depth map. Defaults to "Spectral". Set to `None` to skip colormap generation.
# show_progress_bar=True, # (optional) If true, will show progress bars of the inference progress. # show_progress_bar=True, # (optional) If true, will show progress bars of the inference progress.
) )
......
...@@ -50,14 +50,14 @@ class MarigoldDepthOutput(BaseOutput): ...@@ -50,14 +50,14 @@ class MarigoldDepthOutput(BaseOutput):
Args: Args:
depth_np (`np.ndarray`): depth_np (`np.ndarray`):
Predicted depth map, with depth values in the range of [0, 1]. Predicted depth map, with depth values in the range of [0, 1].
depth_colored (`PIL.Image.Image`): depth_colored (`None` or `PIL.Image.Image`):
Colorized depth map, with the shape of [3, H, W] and values in [0, 1]. Colorized depth map, with the shape of [3, H, W] and values in [0, 1].
uncertainty (`None` or `np.ndarray`): uncertainty (`None` or `np.ndarray`):
Uncalibrated uncertainty(MAD, median absolute deviation) coming from ensembling. Uncalibrated uncertainty(MAD, median absolute deviation) coming from ensembling.
""" """
depth_np: np.ndarray depth_np: np.ndarray
depth_colored: Image.Image depth_colored: Union[None, Image.Image]
uncertainty: Union[None, np.ndarray] uncertainty: Union[None, np.ndarray]
...@@ -139,14 +139,15 @@ class MarigoldPipeline(DiffusionPipeline): ...@@ -139,14 +139,15 @@ class MarigoldPipeline(DiffusionPipeline):
If set to 0, the script will automatically decide the proper batch size. If set to 0, the script will automatically decide the proper batch size.
show_progress_bar (`bool`, *optional*, defaults to `True`): show_progress_bar (`bool`, *optional*, defaults to `True`):
Display a progress bar of diffusion denoising. Display a progress bar of diffusion denoising.
color_map (`str`, *optional*, defaults to `"Spectral"`): color_map (`str`, *optional*, defaults to `"Spectral"`, pass `None` to skip colorized depth map generation):
Colormap used to colorize the depth map. Colormap used to colorize the depth map.
ensemble_kwargs (`dict`, *optional*, defaults to `None`): ensemble_kwargs (`dict`, *optional*, defaults to `None`):
Arguments for detailed ensembling settings. Arguments for detailed ensembling settings.
Returns: Returns:
`MarigoldDepthOutput`: Output class for Marigold monocular depth prediction pipeline, including: `MarigoldDepthOutput`: Output class for Marigold monocular depth prediction pipeline, including:
- **depth_np** (`np.ndarray`) Predicted depth map, with depth values in the range of [0, 1] - **depth_np** (`np.ndarray`) Predicted depth map, with depth values in the range of [0, 1]
- **depth_colored** (`PIL.Image.Image`) Colorized depth map, with the shape of [3, H, W] and values in [0, 1] - **depth_colored** (`None` or `PIL.Image.Image`) Colorized depth map, with the shape of [3, H, W] and
values in [0, 1]. None if `color_map` is `None`
- **uncertainty** (`None` or `np.ndarray`) Uncalibrated uncertainty(MAD, median absolute deviation) - **uncertainty** (`None` or `np.ndarray`) Uncalibrated uncertainty(MAD, median absolute deviation)
coming from ensembling. None if `ensemble_size = 1` coming from ensembling. None if `ensemble_size = 1`
""" """
...@@ -233,12 +234,15 @@ class MarigoldPipeline(DiffusionPipeline): ...@@ -233,12 +234,15 @@ class MarigoldPipeline(DiffusionPipeline):
depth_pred = depth_pred.clip(0, 1) depth_pred = depth_pred.clip(0, 1)
# Colorize # Colorize
if color_map is not None:
depth_colored = self.colorize_depth_maps( depth_colored = self.colorize_depth_maps(
depth_pred, 0, 1, cmap=color_map depth_pred, 0, 1, cmap=color_map
).squeeze() # [3, H, W], value in (0, 1) ).squeeze() # [3, H, W], value in (0, 1)
depth_colored = (depth_colored * 255).astype(np.uint8) depth_colored = (depth_colored * 255).astype(np.uint8)
depth_colored_hwc = self.chw2hwc(depth_colored) depth_colored_hwc = self.chw2hwc(depth_colored)
depth_colored_img = Image.fromarray(depth_colored_hwc) depth_colored_img = Image.fromarray(depth_colored_hwc)
else:
depth_colored_img = None
return MarigoldDepthOutput( return MarigoldDepthOutput(
depth_np=depth_pred, depth_np=depth_pred,
depth_colored=depth_colored_img, depth_colored=depth_colored_img,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment