keras-team / keras-cv

Industry-strength Computer Vision workflows with Keras
Other
1.01k stars 330 forks source link

BUG in stable_diffusion.image_encoder.ImageEncoder creates edge padding on encoded image. #1172

Closed bobqywei closed 1 year ago

bobqywei commented 1 year ago

This was found when debugging: https://github.com/keras-team/keras-cv/issues/1158 and is likely the root cause.

The pretrained image encoder adds zero padding to the top and left edges of the image when encoding. This can be reproduced and seen as follows:

Screenshot 2022-12-20 at 12 24 43 PM

The original image is transformed via out = decoder(encoder(img)) resulting in an output image that is visually identical other than the gray border at the top and left edges. Furthermore, we can likely assume that there's no problem with the decoder since that is being used in the standard StableDiffusion.text_to_image function which does not have this issue visually.

LukeWood commented 1 year ago

I've confirmed that the decoder does in fact create an 8px padding on the top left which is incorrect:

https://colab.research.google.com/drive/1XR7Rs-mLZBeQI3_9c7p3lr_LJ65bJjJD?usp=sharing

LukeWood commented 1 year ago

more info at https://github.com/keras-team/keras-cv/issues/1158

LukeWood commented 1 year ago

Notes for Ian/Francois/Myself:

ianstenbit commented 1 year ago

Re-opening as I rolled back the fix, which caused a separate issue with inpainting.

LukeWood commented 1 year ago

Asked in https://github.com/divamgupta/stable-diffusion-tensorflow/issues/71

LukeWood commented 1 year ago

No borders in https://colab.research.google.com/drive/1Bf-bNmAdtQhPcYNyC-guu0uTu9MYYfLu?usp=sharing