Skip to content

[bug]: Using ESRGAN-upscaled images on Unified Canvas doesn't work as expected #1604

Closed
@psychedelicious

Description

@psychedelicious

Is there an existing issue for this?

  • I have searched the existing issues

OS

macOS

GPU

mps

VRAM

32GB

What happened?

To reproduce

  • Generate or upload an image
  • Upscale it using ESRGAN with any scale and any strength > 0
  • Send it to canvas
  • Position bounding box entirely within the image
  • Click invoke (any settings)

Results

  1. The image is outpainted instead of img2img'd.

  2. An error like this is in my terminal on MPS:

/Users/spencer/Documents/Code/stable-diffusion/ldm/invoke/generator/base.py:144: RuntimeWarning: Mean of empty slice.
  init_means = np_init_rgb_pixels_masked.mean(axis=0)
/Users/spencer/mambaforge/envs/invokeai/lib/python3.10/site-packages/numpy/core/_methods.py:265: RuntimeWarning: Degrees of freedom <= 0 for slice
  ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
/Users/spencer/Documents/Code/stable-diffusion/ldm/invoke/generator/base.py:146: RuntimeWarning: Mean of empty slice.
  gen_means = np_image_masked.mean(axis=0)
  1. On MPS, the result image is totally black. On CUDA, it appears to have messed up colors.

Examples

CUDA on Linux (thanks @JPPhoto)

Canvas state:
image

Result:
image

MPS

Canvas state:
image

Representation of transparency in the bounding box area:
image

Result:
image

Investigation

Root cause is ESRGAN (or our implementation) introduces many partially transparent pixels, scattered across the whole image, to the upscaled image.

We see that transparency and run outpainting on the transparent pixels.

Then we do seam painting on all the seams around all of the transparent pixels. This results in the whole image being seam-painted, which means the whole image gets img2img'd.

This non-fatally fails for some reason, resulting in a black output image on MPS and one with messed up colors on CUDA on Linux.

Solutions

We need to do both of these.

  1. Fix ESRGAN outputs to not introduce transparency.

  2. Fix inpainting so that it does not fail in the edge case of many scattered transparent pixels.

Screenshots

No response

Additional context

No response

Contact Details

No response

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions