ThereforeGames / unprompted

Templating language written for Stable Diffusion workflows. Available as an extension for the Automatic1111 WebUI.
777 stars 66 forks source link

img2mask Not working after today's Auto1111 update #33

Closed Ev-Bro closed 1 year ago

Ev-Bro commented 1 year ago

I am a giant fan of img2mask! I was using it a bunch yesterday. Its stopped working after Auto1111 update today.

Error running process: C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\scripts\unprompted.py
Traceback (most recent call last):
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 133, in render
    return str(self.handler(self.token.keyword, self.pargs, self.kwargs, context, content))
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shared.py", line 57, in handler
    return(self.shortcode_objects[f"{keyword}"].run_block(pargs, kwargs, context, content))
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted/shortcodes\stable_diffusion\txt2mask.py", line 149, in run_block
    self.image_mask = get_mask().resize((self.Unprompted.shortcode_user_vars["init_images"][0].width,self.Unprompted.shortcode_user_vars["init_images"][0].height))
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted/shortcodes\stable_diffusion\txt2mask.py", line 102, in get_mask
    img = transform(self.Unprompted.shortcode_user_vars["init_images"][0]).unsqueeze(0)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\transforms.py", line 94, in __call__
    img = t(img)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\transforms.py", line 269, in forward
    return F.normalize(tensor, self.mean, self.std, self.inplace)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\functional.py", line 360, in normalize
    return F_t.normalize(tensor, mean=mean, std=std, inplace=inplace)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\functional_tensor.py", line 959, in normalize
    tensor.sub_(mean).div_(std)
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\modules\scripts.py", line 338, in process
    script.process(p, *script_args)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\scripts\unprompted.py", line 105, in process
    Unprompted.shortcode_user_vars["prompt"] = Unprompted.process_string(apply_prompt_template(original_prompt,Unprompted.Config.templates.default))
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shared.py", line 77, in process_string
    string = self.shortcode_parser.parse(string,context)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 219, in parse
    return stack.pop().render(context)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 58, in render
    return ''.join(child.render(context) for child in self.children)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 58, in <genexpr>
    return ''.join(child.render(context) for child in self.children)
  File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 137, in render
    raise ShortcodeRenderingError(msg) from ex
lib.shortcodes.ShortcodeRenderingError: An exception was raised while rendering the 'txt2mask' shortcode in line 1.
ThereforeGames commented 1 year ago

Hi @Ev-Bro,

Thank you for reaching out!

It looks like A1111 has been updating the UI a lot today. I just grabbed the latest version and it looks like the txt2mask shortcode is working correctly - maybe the bug was already resolved?

If the error persists on your end, please let me know your exact prompt and inference settings if you don't mind. Thanks!

Ev-Bro commented 1 year ago

Thanks for the reply. Same issue today after pull some more Auto1111 updates. I tried reinstalling the extension with no luck. I have not tried a full Auto1111 reinstall.

What are inference settings?

Here is my prompt: [txt2mask smoothing=10]black dress[/txt2mask] red dress

error:

Error running process: C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\scripts\unprompted.py Traceback (most recent call last): File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 133, in render return str(self.handler(self.token.keyword, self.pargs, self.kwargs, context, content)) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shared.py", line 57, in handler return(self.shortcode_objects[f"{keyword}"].run_block(pargs, kwargs, context, content)) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted/shortcodes\stable_diffusion\txt2mask.py", line 149, in run_block self.image_mask = get_mask().resize((self.Unprompted.shortcode_user_vars["init_images"][0].width,self.Unprompted.shortcode_user_vars["init_images"][0].height)) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted/shortcodes\stable_diffusion\txt2mask.py", line 102, in get_mask img = transform(self.Unprompted.shortcode_user_vars["init_images"][0]).unsqueeze(0) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\transforms.py", line 94, in call img = t(img) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\transforms.py", line 269, in forward return F.normalize(tensor, self.mean, self.std, self.inplace) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\functional.py", line 360, in normalize return F_t.normalize(tensor, mean=mean, std=std, inplace=inplace) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\venv\lib\site-packages\torchvision\transforms\functionaltensor.py", line 959, in normalize tensor.sub(mean).div_(std) RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\modules\scripts.py", line 338, in process script.process(p, *script_args) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\scripts\unprompted.py", line 105, in process Unprompted.shortcode_user_vars["prompt"] = Unprompted.process_string(apply_prompt_template(original_prompt,Unprompted.Config.templates.default)) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shared.py", line 77, in process_string string = self.shortcode_parser.parse(string,context) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 219, in parse return stack.pop().render(context) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 58, in render return ''.join(child.render(context) for child in self.children) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 58, in return ''.join(child.render(context) for child in self.children) File "C:\Users\username\AUTOMATIC1111\stable-diffusion-webui\extensions\unprompted\lib\shortcodes.py", line 137, in render raise ShortcodeRenderingError(msg) from ex lib.shortcodes.ShortcodeRenderingError: An exception was raised while rendering the 'txt2mask' shortcode in line 1.

credman0 commented 1 year ago

I just installed the extension and can confirm I am having the same problem. I don't want to set you on the wrong path, but I suspect that somehow it is getting an RGBA image now instead of RGB, which is consistent with some changes in the webui having to do with allowing customization in the bg color.

Webui has a new flatten function and seems like it had to be fixed in other places e.g.: https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/c6f347b81f584b6c0d44af7a209983284dbb52d2

which at a cursory glance looks a little like what is happening where this bug is here. The flatten function (I believe) is new, maybe you need to do something similar now as well.

I don't have any way to debug right now to test this, unfortunately...

ThereforeGames commented 1 year ago

Fixed in v5.0.0. Thank you!