stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: TypeError: 'NoneType' object is not subscriptable when using img2img alternative test

Open matrix4767 opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

Webui fails to generate an image if using the img2img alternative test since the runway inpainting support update. Unrelated to this, it does not support the unlimited tokens either.

Steps to reproduce the problem

  1. Go to imgimg
  2. Choose img2img alternative test
  3. Upload image and write prompt, parameters, settings, etc.
  4. Generate.

What should have happened?

An image should generate.

Commit where the problem happens

bf30673f5132c8f28357b31224c54331e788d3e7

What platforms do you use to access UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

--deepdanbooru --xformers --gradio-img2img-tool color-sketch

Additional information, context and logs

Traceback (most recent call last): File "G:\stable-webui\modules\ui.py", line 212, in f res = list(func(*args, **kwargs)) File "G:\stable-webui\webui.py", line 63, in f res = func(*args, **kwargs) File "G:\stable-webui\modules\img2img.py", line 124, in img2img processed = modules.scripts.scripts_img2img.run(p, *args) File "G:\stable-webui\modules\scripts.py", line 173, in run processed = script.run(p, *script_args) File "G:\stable-webui\scripts\img2imgalt.py", line 208, in run processed = processing.process_images(p) File "G:\stable-webui\modules\processing.py", line 411, in process_images samples_ddim = p.sample(conditioning=c, unconditional_conditioning=uc, seeds=seeds, subseeds=subseeds, subseed_strength=p.subseed_strength) File "G:\stable-webui\scripts\img2imgalt.py", line 197, in sample_extra return sampler.sample_img2img(p, p.init_latent, noise_dt, conditioning, unconditional_conditioning) File "G:\stable-webui\modules\sd_samplers.py", line 423, in sample_img2img samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, xi, extra_args={ File "G:\stable-webui\modules\sd_samplers.py", line 356, in launch_sampling return func() File "G:\stable-webui\modules\sd_samplers.py", line 423, in samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, xi, extra_args={ File "G:\stable-webui\venv\lib\site-packages\torch\autograd\grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "G:\stable-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 64, in sample_euler denoised = model(x, sigma_hat * s_in, **extra_args) File "G:\stable-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "G:\stable-webui\modules\sd_samplers.py", line 269, in forward image_cond_in = torch.cat([torch.stack([image_cond[i] for _ in range(n)]) for i, n in enumerate(repeats)] + [image_cond]) File "G:\stable-webui\modules\sd_samplers.py", line 269, in image_cond_in = torch.cat([torch.stack([image_cond[i] for _ in range(n)]) for i, n in enumerate(repeats)] + [image_cond]) File "G:\stable-webui\modules\sd_samplers.py", line 269, in image_cond_in = torch.cat([torch.stack([image_cond[i] for _ in range(n)]) for i, n in enumerate(repeats)] + [image_cond]) TypeError: 'NoneType' object is not subscriptable

matrix4767 avatar Oct 21 '22 08:10 matrix4767

Error is caused the line below not handling image_cond being uninitialised. https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/f49c08ea566385db339c6628f65c3a121033f67c/modules/sd_samplers.py#L269

Putting an IF check fixes the issue for the img2imgalt script but I'm not sure what this line is meant to do which is a question for @random-thoughtss

        image_cond_in = None
        if image_cond is not None:
            image_cond_in = torch.cat([torch.stack([image_cond[i] for _ in range(n)]) for i, n in enumerate(repeats)] + [image_cond])

MartinCairnsSQL avatar Oct 21 '22 17:10 MartinCairnsSQL

Setting it to None would crash the in-painting model and would break if there is any batch size or large prompt.

This is the diff for the fix. Just need to add image conditioning to the img2imgalt script since it bypasses the regular img2img sampling call.

https://gist.github.com/random-thoughtss/f3ba564f4b7840136107763bdad26541

random-thoughtss avatar Oct 21 '22 18:10 random-thoughtss