Repository navigation
How to generate white background images instead of colorful? #14813
Replies: 4 comments 1 reply
|
Your load_square() function does composite transparent inputs onto white, so BG_COLOR itself is not an inference-time background control. The result means the LoRA/text conditioning has not learned “white background” strongly enough to override SD 1.5’s background prior. I would debug it in this order:
A UNet attention LoRA is good at learning style/concepts but is not a pixel-level background guarantee. If production output must be exactly #FFFFFF, the reliable solution is segmentation/alpha extraction followed by compositing onto white (or an explicit conditioning/mask workflow). Use the LoRA for the asset style and enforce the final background deterministically in post-processing. |
|
Chances are your transparent PNGs aren't actually being composited onto white. Composite explicitly: img = Image.open(path).convert("RGBA")
bg = Image.new("RGBA", img.size, (255, 255, 255, 255))
img = Image.alpha_composite(bg, img).convert("RGB")Do that and the caption "white background" actually matches the pixels. Without it, the model learns the weird under-alpha colors and no prompt text will fix that at inference. Also check a few decoded training images to confirm the background is really white before burning a training run. — |
|
Your SD 1.5's noise schedule never fully wipes out the image, even at the last timestep ( I measured this on the SD 1.5 VAE: a pure white image's latent channel mean sits about 9.5 noise standard deviations from zero at the last timestep, so the UNet can clearly read it. The cheap fix is offset noise, which the official LoRA script exposes as noise = torch.randn_like(latents)
noise += 0.1 * torch.randn((latents.shape[0], latents.shape[1], 1, 1), device=latents.device, dtype=latents.dtype)Your loss already targets that same If you need exact #FFFFFF, background removal is still the only guarantee. I haven't trained your setup, so that A/B will tell you how much this helps. |

















Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi, I'm trying to train stable-diffusion-v1-5/stable-diffusion-v1-5 with custom data with LoraConfig to generate a type of 2D asset.
So I have a dataset of transparent PNG images, and I added to my prompt text for every image a white background after the caption
And in my script, I added BG_COLOR = (255, 255, 255)
and that's my code
But I got this image
thanks and regards
All reactions