fix marigold

Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
Vladimir Mandic
2025-11-12 14:32:04 -05:00
parent 7c5d1505b8
commit 05008b332f
4 changed files with 8 additions and 5 deletions
+1
View File
@@ -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
+2 -1
View File
@@ -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,
@@ -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:
@@ -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(