lllyasviel / sd-forge-layerdiffuse

[WIP] Layer Diffusion for WebUI (via Forge)
Apache License 2.0
3.86k stars 331 forks source link

Transparency with Highres Fix Doesn't work anymore #119

Open MimoletteRobot opened 3 months ago

MimoletteRobot commented 3 months ago

Hello

When i'm using Highres Fix, the image doesn't get transparency. That worked few day ago with the same setting.

I got this error (i don't know if this related) :

Error running postprocess_image_after_composite: /content/drive/MyDrive/stable-diffusion-webui-forge/extensions/sd-forge-layerdiffuse/scripts/forge_layerdiffusion.py Traceback (most recent call last): File "/content/drive/MyDrive/stable-diffusion-webui-forge/modules/scripts.py", line 956, in postprocess_image_after_composite script.postprocess_image_after_composite(p, pp, script_args) File "/content/drive/MyDrive/stable-diffusion-webui-forge/extensions/sd-forge-layerdiffuse/scripts/forge_layerdiffusion.py", line 376, in postprocess_image_after_composite png, vis = vae_transparent_decoder.decode(latent, pixel) File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(args, kwargs) File "/content/drive/MyDrive/stable-diffusion-webui-forge/extensions/sd-forge-layerdiffuse/lib_layerdiffusion/models.py", line 278, in decode y = self.estimate_augmented(pixel, latent) File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "/content/drive/MyDrive/stable-diffusion-webui-forge/extensions/sd-forge-layerdiffuse/lib_layerdiffusion/models.py", line 259, in estimate_augmented eps = self.estimate_single_pass(feed_pixel, feed_latent).clip(0, 1) File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(args, kwargs) File "/content/drive/MyDrive/stable-diffusion-webui-forge/extensions/sd-forge-layerdiffuse/lib_layerdiffusion/models.py", line 237, in estimate_single_pass y = self.model.model(pixel, latent) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, *kwargs) File "/content/drive/MyDrive/stable-diffusion-webui-forge/extensions/sd-forge-layerdiffuse/lib_layerdiffusion/models.py", line 159, in forward sample_latent = self.latent_conv_in(latent) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/conv.py", line 460, in forward return self._conv_forward(input, self.weight, self.bias) File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/conv.py", line 456, in _conv_forward return F.conv2d(input, weight, bias, self.stride, RuntimeError: Given groups=1, weight of size [64, 4, 1, 1], expected input[1, 3, 268, 268] to have 4 channels, but got 3 channels instead

D-a-r-n-o-l-d commented 2 months ago

are you doing higher than 1024/1024 res?

MimoletteRobot commented 2 months ago

With Highres Fix yes : 2048/2048 (upscale 2), with original generation at 1024/1024. This setting worked perfectly with transparency before. Now i have just grey background.

D-a-r-n-o-l-d commented 2 months ago

ive never had a gen work higher than 1024/1024

MimoletteRobot commented 2 months ago

I have thousand of generation in 2048/2048 with transparency, working with SDXL/Pony/SDXL Lighting.

00270-4088350647 00040-1453487442

MimoletteRobot commented 2 months ago

The creator of layerdiffusion knows that it could be used with Highres fix? Its strange that i'm the only one with this problem, and I can't contact him directly it's sad

srg91 commented 2 months ago

The creator of layerdiffusion knows that it could be used with Highres fix? Its strange that i'm the only one with this problem, and I can't contact him directly it's sad

Hello,

You're not the only one who encountered this problem; I faced it as well.

I don't fully understand how this works, but as far as I can tell, the main issue is that TransparentVAEDecoder expects 4 channels as input, while after Hires.Fix, only 3 channels are provided.

I fixed it by setting 4 channels in this section:

diff --git a/scripts/forge_layerdiffusion.py b/scripts/forge_layerdiffusion.py
index 7efba7b..05567b4 100644
--- a/scripts/forge_layerdiffusion.py
+++ b/scripts/forge_layerdiffusion.py
@@ -370,6 +370,11 @@ class LayerDiffusionForForge(scripts.Script):
             lC, lH, lW = latent.shape
             if lH != pixel.height // 8 or lW != pixel.width // 8:
                 print('[LayerDiffuse] VAE zero latent mode.')
+
+                if lC < 4:
+                    print('[LayerDiffuse] VAE expecting 4 channels.')
+                    lC = 4
+
                 latent = torch.zeros((lC, pixel.height // 8, pixel.width // 8)).to(latent)

             png, vis = vae_transparent_decoder.decode(latent, pixel)

This fixes the issue, but I haven't tested it in all possible cases. So, use this code at your own risk.

Thank you.

MimoletteRobot commented 2 months ago

Thanks to you ! it's Work !

MimoletteRobot commented 2 months ago

Since The last Update, Here we Go again. With the update, layer diffusion seem to make the same think than before with channel, and the last fix on this thread doesn't work anymore.

srg91 commented 2 months ago

Since The last Update, Here we Go again. With the update, layer diffusion seem to make the same think than before with channel, and the last fix on this thread doesn't work anymore.

My fix still works, you just need to apply it again after the update. It's more of a patch than a full fix.

And please don't close the issue, let the author see the problem too.

Thank you.

MimoletteRobot commented 2 months ago

Yes it's work ! i made this the first time (false manipulation i guess) but having transparency at random place , i dit it again and now that's fine. I'm new to Github and Join for this Issue, I didn't know what to do with the thread, i let it open. The Author should do a Ko-Fi or Github a System of Tips so lllyasviel can Delegate thing like that or tips can get moving people to share, and people with no coding skill like me can participate and fuel the process.

zffffff commented 1 month ago

The creator of layerdiffusion knows that it could be used with Highres fix? Its strange that i'm the only one with this problem, and I can't contact him directly it's sad

Hello,

You're not the only one who encountered this problem; I faced it as well.

I don't fully understand how this works, but as far as I can tell, the main issue is that TransparentVAEDecoder expects 4 channels as input, while after Hires.Fix, only 3 channels are provided.

I fixed it by setting 4 channels in this section:

diff --git a/scripts/forge_layerdiffusion.py b/scripts/forge_layerdiffusion.py
index 7efba7b..05567b4 100644
--- a/scripts/forge_layerdiffusion.py
+++ b/scripts/forge_layerdiffusion.py
@@ -370,6 +370,11 @@ class LayerDiffusionForForge(scripts.Script):
             lC, lH, lW = latent.shape
             if lH != pixel.height // 8 or lW != pixel.width // 8:
                 print('[LayerDiffuse] VAE zero latent mode.')
+
+                if lC < 4:
+                    print('[LayerDiffuse] VAE expecting 4 channels.')
+                    lC = 4
+
                 latent = torch.zeros((lC, pixel.height // 8, pixel.width // 8)).to(latent)

             png, vis = vae_transparent_decoder.decode(latent, pixel)

This fixes the issue, but I haven't tested it in all possible cases. So, use this code at your own risk.

Thank you.

i got this

[LayerDiffuse] VAE zero latent mode. ** Error running postprocess_image_after_composite: D:\sdwebui\webui_forge_cu121_torch21a\webui\extensions\sd-forge-layerdiffuse\scripts\forge_layerdiffusion.py Traceback (most recent call last): File "D:\sdwebui\webui_forge_cu121_torch21a\webui\modules\scripts.py", line 956, in postprocess_image_after_composite script.postprocess_image_after_composite(p, pp, script_args) File "D:\sdwebui\webui_forge_cu121_torch21a\webui\extensions\sd-forge-layerdiffuse\scripts\forge_layerdiffusion.py", line 374, in postprocess_image_after_composite if IC < 4: UnboundLocalError: local variable 'IC' referenced before assignment