sddebz / stable-diffusion-krita-plugin

GNU Affero General Public License v3.0
423 stars 34 forks source link

Inpainting Does Not Work #8

Closed 503Dev closed 2 years ago

503Dev commented 2 years ago

Environment WIndows 11 Krita 5.1.0 Stable-Diffusion-Krita-Plugib - Latest git pull

Steps to Reproduce

  1. Start with an image
  2. Create a new layer
  3. Paint an area on the new layer
  4. Select the SD Plugin -> img2img tab
  5. Enter a prompt
  6. Press "Apply SD Inpainting"

Error Logs From terminal (server / krita.bat) img2img: mode=1 src_path='D:\\krita-plugins\\stable-diffusion-krita-plugin\\outputs\\krita-in\\1662275269.png' mask_path='D:\\krita-plugins\\stable-diffusion-krita-plugin\\outputs\\krita-in\\1662275269_mask.png' prompt='death star' sampler_name='k_euler_a' steps=50 cfg_scale=12.0 denoising_strength=0.4 batch_count=1 batch_size=1 base_size=512 max_size=704 seed='' normalize_prompt_weights=None use_gfpgan=None use_realesrgan=None realesrgan_model=None upscale_overlap=None inpainting_fill=None inpaint_full_res=None mask_blur=None img size: 512x512 -> 512x512 INFO: 127.0.0.1:61278 - "POST /img2img HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 404, in run_asgi result = await app( # type: ignore[func-returns-value] File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__ return await self.app(scope, receive, send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\fastapi\applications.py", line 269, in __call__ await super().__call__(scope, receive, send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\applications.py", line 124, in __call__ await self.middleware_stack(scope, receive, send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__ raise exc File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__ await self.app(scope, receive, _send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\exceptions.py", line 93, in __call__ raise exc File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\exceptions.py", line 82, in __call__ await self.app(scope, receive, sender) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__ raise e File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__ await self.app(scope, receive, send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\routing.py", line 670, in __call__ await route.handle(scope, receive, send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\routing.py", line 266, in handle await self.app(scope, receive, send) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\starlette\routing.py", line 65, in app response = await func(request) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\fastapi\routing.py", line 231, in app raw_response = await run_endpoint_function( File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\fastapi\routing.py", line 160, in run_endpoint_function return await dependant.call(**values) File "D:\krita-plugins\stable-diffusion-krita-plugin\krita_server.py", line 204, in f_img2img output_images, info, html = modules.img2img.img2img( File "D:\krita-plugins\stable-diffusion-krita-plugin\modules\img2img.py", line 135, in img2img processed = process_images(p) File "D:\krita-plugins\stable-diffusion-krita-plugin\modules\processing.py", line 148, in process_images p.init() File "D:\krita-plugins\stable-diffusion-krita-plugin\modules\processing.py", line 314, in init mask = mask.crop(crop_region) File "D:\krita-plugins\stable-diffusion-krita-plugin\venv\lib\site-packages\PIL\Image.py", line 1171, in crop raise ValueError("Coordinate 'right' is less than 'left'") ValueError: Coordinate 'right' is less than 'left'

sddebz commented 2 years ago

I changed option inpaint_full_res from True to False. This should be fixed now.

inpaint_full_res = False is better because you can select area manually with Krita selection tools. Implementation should not ignore it and crop image futher, I think.

503Dev commented 2 years ago

@sddebz Thanks for the reply and your amazing work. I can confirm on the latest pull that inpainting does now work however results are very poor, blurry and not great however this may be a limitation of SD and not your plugin.

sddebz commented 2 years ago

In my experience inpainting need high denoising strength. 0.6-0.9 should be fine. If you use less, it tends to generate empty areas, if you go for 1.0 it ignores border conditions.

There is also possibility that you didn't select layer with a mask or your mask is not white color. I got similar problem if I accidentally select one of generated layers instead of mask layer.