From 05008b332f7b9b9e2f4a592b5df6ddf6d08cfcee Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Wed, 12 Nov 2025 14:32:04 -0500 Subject: [PATCH] fix marigold Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 1 + modules/control/proc/marigold/__init__.py | 3 ++- modules/control/proc/marigold/marigold_pipeline.py | 2 +- modules/control/proc/marigold/util/ensemble.py | 7 ++++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5227d872d..89043cab5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ TBD - ui: fix collapsible panels - process: improve send-to functionality - control: safe load non-sparse controlnet + - control: fix marigold preprocessor with bfloat16 - auth: fix password being shown in clear text during login ## Update for 2025-11-06 diff --git a/modules/control/proc/marigold/__init__.py b/modules/control/proc/marigold/__init__.py index 6ea346430..af29be777 100644 --- a/modules/control/proc/marigold/__init__.py +++ b/modules/control/proc/marigold/__init__.py @@ -1,3 +1,4 @@ +import torch from PIL import Image from modules.control.util import HWC3, resize_image from modules import devices @@ -28,7 +29,7 @@ class MarigoldDetector: color_map: str = "Spectral", output_type=None, ): - self.model.to(device=devices.device, dtype=devices.dtype) + self.model.to(device=devices.device, dtype=torch.float16) res = self.model( input_image, denoising_steps=denoising_steps, diff --git a/modules/control/proc/marigold/marigold_pipeline.py b/modules/control/proc/marigold/marigold_pipeline.py index a8cec453e..ac60f833e 100644 --- a/modules/control/proc/marigold/marigold_pipeline.py +++ b/modules/control/proc/marigold/marigold_pipeline.py @@ -228,7 +228,7 @@ class MarigoldPipeline(DiffusionPipeline): depth_pred = (depth_pred - min_d) / (max_d - min_d) # Convert to numpy - depth_pred = depth_pred.cpu().numpy().astype(np.float32) + depth_pred = depth_pred.to(torch.float32).cpu().numpy() # Resize back to original resolution if match_input_res: diff --git a/modules/control/proc/marigold/util/ensemble.py b/modules/control/proc/marigold/util/ensemble.py index d7a9023ca..710db1cc2 100644 --- a/modules/control/proc/marigold/util/ensemble.py +++ b/modules/control/proc/marigold/util/ensemble.py @@ -64,8 +64,9 @@ def ensemble_depths( input_images = downscaler(torch.from_numpy(input_images)).numpy() # init guess - _min = np.min(input_images.reshape((n_img, -1)).cpu().numpy(), axis=1) - _max = np.max(input_images.reshape((n_img, -1)).cpu().numpy(), axis=1) + np_img = input_images.reshape((n_img, -1)).to(torch.float32).cpu().numpy() + _min = np.min(np_img, axis=1) + _max = np.max(np_img, axis=1) s_init = 1.0 / (_max - _min).reshape((-1, 1, 1)) t_init = (-1 * s_init.flatten() * _min.flatten()).reshape((-1, 1, 1)) x = np.concatenate([s_init, t_init]).reshape(-1).astype(np_dtype) @@ -95,7 +96,7 @@ def ensemble_depths( far_err = torch.sqrt((1 - torch.max(pred)) ** 2) err = sqrt_dist + (near_err + far_err) * regularizer_strength - err = err.detach().cpu().numpy().astype(np_dtype) + err = err.to(torch.float32).detach().cpu().numpy().astype(np_dtype) return err res = minimize(