Skip to content

Conversation

@psychedelicious
Copy link
Contributor

Our Codeformer and GFPGAN implementations are sending RGB image data to the restoration code, but they expect BGR image data (as used by OpenCV).

The fix is simple; use a cv2 method to convert the image from RGB to BGR before processing, and then back to RGB so we can continue using PIL.

This fixes an until-today unknown flaw in our GFPGAN implementation, which was recognized by user JoshuaKimsey on discord.

@keturn
Copy link
Contributor

keturn commented Oct 20, 2022

I guess there's no harm in using cv2 for this if it's already a project dependency, but does Pillow have any modes that work for this built-in? Maybe BGR;24 or BGR;32?

https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes

@hipsterusername
Copy link
Member

Great find!

Copy link
Member

@hipsterusername hipsterusername left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm! Seems like a simple whoops😅

@psychedelicious
Copy link
Contributor Author

I guess there's no harm in using cv2 for this if it's already a project dependency, but does Pillow have any modes that work for this built-in? Maybe BGR;24 or BGR;32?

https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes

Good catch - I tried "BGR" first and it didn't work, shoulda checked the docs. I'll give this a whirl.

Copy link
Collaborator

@lstein lstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on finding and fixing the problem!

@lstein lstein merged commit 4101127 into invoke-ai:development Oct 20, 2022
@lstein
Copy link
Collaborator

lstein commented Oct 20, 2022

We already use cv2 so there's no particular advantage to doing this in Pillow, but if you want to, go ahead.

@NewandOldDesign
Copy link

I had blue tint on the final rendered image when using restore face on a M1 Mac. After research and messing around I found this solution.
Download the following manually and place them in to their corresponding folder and rename the file as necessary.

https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth to /stable-diffusion-webui/models/Codeformer/codeformer-v0.1.0.pth

https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth to /stable-diffusion-webui/repositories/CodeFormer/weights/facelib/detection_Resnet50_Final.pth

https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth to /stable-diffusion-webui/repositories/CodeFormer/weights/facelib/parsing_parsenet.pt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants