Skip to content
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

Fix a bug of flip in SDXL training script #6547

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

haofanwang
Copy link
Contributor

What does this PR do?

Fixes a problem mentioned in #4632 (comment). For now, the crop condition is problematic because of the flip operation.

First, the following lines should be changed from

image = crop(image, y1, x1, h, w)
if args.random_flip and random.random() < 0.5:
    # flip
    x1 = image.width - x1 # here, image.width is not in original state, but in cropped image state
    image = train_flip(image)

to

orig_width = image.width
image = crop(image, y1, x1, h, w)
if args.random_flip and random.random() < 0.5:
    # flip
    x1 = orig_width - x1 # the width should be in original state
    image = train_flip(image)

Then, to avoid confusion about the coordinates order, it is elegant to conduct flip before crop.

if args.random_flip and random.random() < 0.5:
    # flip
    image = train_flip(image)
image = train_resize(image)

@haofanwang
Copy link
Contributor Author

@sayakpaul

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

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

This indeed simplifies the cognitive load, thank you! It would be nice if we could create a little notebook to explain these conditions better to the community (not needed in this PR, this is me just blaberring).

Copy link
Contributor

@patrickvonplaten patrickvonplaten left a comment

Choose a reason for hiding this comment

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

Nice refactor!

@patrickvonplaten patrickvonplaten merged commit 3d574b3 into huggingface:main Jan 15, 2024
14 checks passed
sayakpaul added a commit that referenced this pull request Jan 22, 2024
sayakpaul added a commit that referenced this pull request Jan 22, 2024
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
* Update train_text_to_image_sdxl.py

* Update train_text_to_image_lora_sdxl.py
AmericanPresidentJimmyCarter pushed a commit to AmericanPresidentJimmyCarter/diffusers that referenced this pull request Apr 26, 2024
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.

3 participants