-
-
Save JaySmithWpg/0dfb716fef567b5fbe8fbebf38dd1101 to your computer and use it in GitHub Desktop.
Hack to load custom depth map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/modules/processing.py b/modules/processing.py | |
index 0417ffc..c2bde57 100644 | |
--- a/modules/processing.py | |
+++ b/modules/processing.py | |
@@ -154,15 +154,17 @@ class StableDiffusionProcessing(): | |
return image_conditioning | |
def depth2img_image_conditioning(self, source_image): | |
- # Use the AddMiDaS helper to Format our source image to suit the MiDaS model | |
- transformer = AddMiDaS(model_type="dpt_hybrid") | |
- transformed = transformer({"jpg": rearrange(source_image[0], "c h w -> h w c")}) | |
- midas_in = torch.from_numpy(transformed["midas_in"][None, ...]).to(device=shared.device) | |
- midas_in = repeat(midas_in, "1 ... -> n ...", n=self.batch_size) | |
+ depth_img = Image.open("/home/jay/Pictures/AI/Turrent Room/depth.png") | |
+ depth_img = depth_img.convert("L") | |
+ depth_img = np.expand_dims(depth_img, axis=0) | |
+ depth_img = np.expand_dims(depth_img, axis=0).repeat(self.batch_size, axis=0) | |
+ depth_img = torch.from_numpy(depth_img) | |
+ depth_img = 2. * depth_img - 1. | |
+ depth_img = depth_img.to(shared.device) | |
conditioning_image = self.sd_model.get_first_stage_encoding(self.sd_model.encode_first_stage(source_image)) | |
conditioning = torch.nn.functional.interpolate( | |
- self.sd_model.depth_model(midas_in), | |
+ depth_img, | |
size=conditioning_image.shape[2:], | |
mode="bicubic", | |
align_corners=False, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1, would be amazing to have this in the the a1111 interface to select a synthetic depth map, instead of computing one using MiDaS