-
Notifications
You must be signed in to change notification settings - Fork 922
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
Some RGBA images cause broken backgrounds due to incorrect RGB conversion #1269
Comments
@feffy380 Interesting, seems like you're right. I kind-of just assumed it was some funky conversion logic but I guess that explains it. I've created a quick script to check for hidden/corrupted backgrounds. Currently testing it against my smaller 300K dataset to see what comes up. The current hit rate is 101 out of ~10000 images, only considering PNGs, so seems pretty rare. |
This is an intended behavior as feffy380 wrote. I think a new option may be needed if we change this, because it is a breaking change. #1223 is still draft, but it will be a good solution for this. |
@kohya-ss Thank you. That solution is indeed more optimal, I'll close my PR and will follow the one you linked instead. |
Currently, the
load_image
function intrain_utils
uses the PILimage.convert("RGB")
method for converting the loaded 4 RGBA channel images to the expected 3 channel RGB format.This is incorrect for some edge cases, and causes the background to become distorted.
As an example, loading this RGBA image results in heavy background artifacts. when used with the test code below:
To verify this issue, a LoRA was created using that single image as the dataset, using a caption that includes the words "white background". Seed and everything else was fixed between the two tests.
The top row is the latest code using a fresh VENV. The bottom row is the proposed fix, which I will create a PR for shortly. It uses the
Image.alpha_composite
function with a new blank white image to handle the alpha channel.The text was updated successfully, but these errors were encountered: