-
Notifications
You must be signed in to change notification settings - Fork 161
support for marigold #385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for marigold #385
Conversation
src/depthmap_generation.py
Outdated
|
||
# From Marigold repository run.py | ||
with torch.no_grad(): | ||
image = (image * 255).astype(np.uint8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to simplify by removing
image = (image * 255).astype(np.uint8)
and turning line 431
rgb = np.transpose(image, (2, 0, 1)) # [H, W, rgb] -> [rgb, H, W]
rgb_norm = rgb / 255.0
into
rgb_norm = np.transpose(image, (2, 0, 1)) # [H, W, rgb] -> [rgb, H, W]
That way we aren't multiplying and dividing 255.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale behind that is that in Marigold they resize the image, and the input of that function is PIL.Image
, so I just thought of having the same option. But yeah, maybe then multiplying and dividing in L427?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does look cleaner to resize with a numpy array using something like
image = cv2.resize(image, (h, w), interpolation=cv2.INTER_CUBIC)
.
Although I'm not sure if there's any subtle differences between cv2 resize and PIL.Image resize.
Great changes overall!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong feeling either way.
Hello and thank you so much for this! I will test as soon as I have time. Meanwhile I will ask for some clarifications... |
@@ -94,8 +94,8 @@ def set_input_train(self, input): | |||
self.real_A = torch.cat((self.outer, self.inner), 1) | |||
|
|||
def set_input(self, outer, inner): | |||
inner = torch.from_numpy(inner).unsqueeze(0).unsqueeze(0) | |||
outer = torch.from_numpy(outer).unsqueeze(0).unsqueeze(0) | |||
inner = torch.from_numpy(inner).unsqueeze(0).unsqueeze(0).float() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you super-duper sure this does not break anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether this break something to be honest. Are there tests/unittests I can run?
I modified this part because for some reason when selecting Marigold mode was raising an error because inner
and outer
were double tensors and the network weights are in float. Not sure why this is a particular error of marigold mode and not for the others.
Overall looks good. I almost did not believe that I stopped short of only 16 lines with my branch - let alone adding boost with the same 16 lines. |
My only concern is that the depthmaps are inverted. In this script, white=near convention is used. I think the only thing to fix that would be adding Marigold (10) to line 298 in depthmap_generation.py: |
Also, would you be so kind to append README with Marigold mentions and an Acknowledgement? Before pushing Marigold support to main we will also need a version bump (misc.py) and a changelog (CHANGELOG.md) with one change. |
I have tested this. It works without boost. Maybe Marigold should be git clone into "extensions/stable-diffusion-webui-depthmap-script/Marigold" rather than "repositories/Marigold" to avoid future conflicts (this is why midas is installed there). Also I believe |
@graemeniedermayer Indeed, it needs |
Also marigold standalone mode doesn't function with the current imports. |
Oh, supporting standalone is definitely needed - a change to requirements.txt. |
Hey folks, I added some of your suggested changes. I am not entirely sure if there was a protocol for the requirements/install files, so let me know what should I change. In particular, I use this project as standalone, so the |
I think this should be merged onto the marigold branch. There might be some small changes/extra testing to do before merging into main. Great work! |
Merged and did some fixes. Now it would be awesome to support automatic repository pull for standalone. Yes, we can just copy all the files into the root again... But I'd rather not have any new code linked this way. |
This is really good news! I also want do draw some attention to equivalent implementation in ComfyUI, and that it implements floating point EXR export:
Which relates to #372 and #370 |
Not now, I am reeeaaally busy. Should be doing my homework rn, in fact. |
@affromero @graemeniedermayer I can't get it to work! Please help... :( GPU: 1080Ti |
Oh I just realized I tested it with a different |
It shouldn't be too challenging to save the numpy arrays is there a library for converting to EXR? |
Apparently so, simply called "OpenEXR". |
Discussion: #379
Issue: #383
I continued the implementation and this is an example: