Skip to content
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

[bug]: Inpaint near image borders creates artifacts along the borders #6349

Open
1 task done
Svyaga opened this issue May 11, 2024 · 5 comments
Open
1 task done

[bug]: Inpaint near image borders creates artifacts along the borders #6349

Svyaga opened this issue May 11, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Svyaga
Copy link

Svyaga commented May 11, 2024

Is there an existing issue for this problem?

  • I have searched the existing issues

Operating system

Windows

GPU vendor

Nvidia (CUDA)

GPU model

RTX 3070

GPU VRAM

8GB

Version number

4.2.0

Browser

Chrome 124.0.6367.158

Python dependencies

{
"accelerate": "0.29.2",
"compel": "2.0.2",
"cuda": "12.1",
"diffusers": "0.27.2",
"numpy": "1.26.4",
"opencv": "4.9.0.80",
"onnx": "1.15.0",
"pillow": "10.2.0",
"python": "3.10.11",
"torch": "2.2.2+cu121",
"torchvision": "0.17.2+cu121",
"transformers": "4.39.3",
"xformers": "0.0.25.post1"
}

What happened

SD: SDXL.
Whenever image is generated during img2img/inpaint process, strange artifacts appear along the borders of the image.
Tested on both Tiled img2img (in "Workflows" mode) and in Canvas mode.

  1. You can see a thin artifact line along the border of the image (top arrow), it was caused by tiled img2img:
    2
    Then I made a slight inpaint (bottom arrow) and tried to inpant. New artifacts along the border appeared:
    3

  2. These artifacts appear even if masked area (for inpaint) is far away from the border. This is the masked area:
    4
    This is before/after inpaint. You can notice that border of the image was changed: https://imgsli.com/MjYyOTkw

What you expected to happen

I expected selected areas to be properly cropped and inpaint to be properly applied without artifacts along borders of the image.

How to reproduce the problem

These steps copy my actions, but there are probably some optional steps like upscaling an image. I will mark them with "*".

  1. Tiled img2img:
    1.1. Generate any image.
    1.2.* Upscale image with x4 upscaler (I used RealESRGAN x4 Plus (anime 6B)
    1.3. Run tiled img2img workflow:
    Tiled img2img.json

  2. Canvas inpaint
    2.1. Generate any image
    2.2.* Upscale image with x4 upscaler (I used RealESRGAN x4 Plus (anime 6B)
    2.3. Put upscaled image in Canvas mode.
    2.4. Select any area of the image, any of the borders of selection box should align with image border.
    2.5.* Mask any area inside the selection box
    2.6. Run inpaint.

Additional context

I noticed that these artifacts appear along the borders during preview of the generation:
1

Discord username

svyaga

@Svyaga Svyaga added the bug Something isn't working label May 11, 2024
@Svyaga
Copy link
Author

Svyaga commented May 11, 2024

Forgot to mention that there was a similar problem in ComfyUI and it was fixed later:
comfyanonymous/ComfyUI#1363

And here's how it was fixed:
comfyanonymous/ComfyUI@bed116a

@Svyaga
Copy link
Author

Svyaga commented May 11, 2024

Seems to be the same problem as in ComfyUI, here are some examples of misaligned pixels in initial generation of 888x1184 image:
Photoshop_TEbnbvMqYM
Photoshop_vl9gAr8HJH
I also should add that this happens on all sides of the borders, but it's more visible on bottom and right borders, especially right one.

@dunkeroni
Copy link
Contributor

The first example does look like an issue I've seen when denoising padded latents, which may be the case if your region dimensions are not multiples of 64. Reflect padding instead of constants usually worked best in my experiments.

Your second example confuses me, because pixels far outside of your mask area are being affected. That looks like VAE nondeterminism to me, but the canvas paste-back operation shouldn't allow that. What is your Mask Blur setting at? Seems like it might be way too high.

@Svyaga
Copy link
Author

Svyaga commented May 12, 2024

The first example does look like an issue I've seen when denoising padded latents, which may be the case if your region dimensions are not multiples of 64. Reflect padding instead of constants usually worked best in my experiments.

Your second example confuses me, because pixels far outside of your mask area are being affected. That looks like VAE nondeterminism to me, but the canvas paste-back operation shouldn't allow that. What is your Mask Blur setting at? Seems like it might be way too high.

  1. Dimensions could be the case for tiled img2img, but not for canvas and especially not the initial generation. I only use automatic dimensions with upscale to 1024x1024 (or similar dimensions for other aspect ratios). I mean the upscale if the selected box is smaller than model preffered dimensions ("Scale before processing" option).

Here's 1024x1024 image without any img2img applied:
a3f72176-ea9d-4c01-9332-d417c30cb4d9
You can notice the misaligned pixels there:
Photoshop_mij50rVRgx

  1. These are my settings for compositing:
    1111
    chrome_nREU2Zpd8u

@Svyaga
Copy link
Author

Svyaga commented May 15, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants