-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Add circular padding for artifact-free StableDiffusionPanoramaPipeline #4025
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
Conversation
The documentation is not available anymore as the PR was closed or merged. |
In general, it's an easy fix for the stitching artifact problem, but maybe I've missed an easier way to do it with the current pipeline. Perhaps this is too narrow case to add this to the main. I've also noticed tests for this pipeline that I break with my changes (even with default I've tried "cuda" and "cpu", different |
@omerbt @sayakpaul @Isotr0py guys, what do you think? |
I will defer to @omerbt for this one. But I like what I see :) |
Looks great! |
Thanks @omerbt! @EvgenyKashin, let's make sure the tests on the CI pass. Then I think we can approach merging. |
Thanks, guys. @sayakpaul I've fixed one place in the code. Basically, I decided to save one line originally, but one more check was required for small images case (like in test cases). I've also added a few simple test cases for circular padding. |
Sorry, originally tagged the wrong person, @sayakpaul |
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py
Outdated
Show resolved
Hide resolved
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_panorama.py
Show resolved
Hide resolved
tests/pipelines/stable_diffusion/test_stable_diffusion_panorama.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! Thank you.
Left some minor nits. One thing we could do is add a note about circular_padding
to the panorama docs: https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/panorama.mdx.
Thanks for the review @sayakpaul, that's improving the PR! I've rewritten the doc-string, added information to the .mdx and removed the slow test. |
Could we merge it? |
Looks amazing @EvgenyKashin! Thanks much for iterating. I just have one more ask here: #4025 (comment) and then we will ship this 🚀. |
@sayakpaul could you approve two images merging to the documentation-images https://huggingface.co/datasets/huggingface/documentation-images/discussions/132 ? |
Will merge after the CI passes. |
@sayakpaul thanks, ready to ship now 🚀 |
Thanks very much for your valuable contributions! |
huggingface#4025) * Add circular padding option * Fix style with black * Fix corner case with small image size * Add circular padding test cases * Fix docstring * Improve docstring for circular padding, remove slow test case * Update docs for circular padding argument * Add images comparison for circular padding
huggingface#4025) * Add circular padding option * Fix style with black * Fix corner case with small image size * Add circular padding test cases * Fix docstring * Improve docstring for circular padding, remove slow test case * Update docs for circular padding argument * Add images comparison for circular padding
huggingface#4025) * Add circular padding option * Fix style with black * Fix corner case with small image size * Add circular padding test cases * Fix docstring * Improve docstring for circular padding, remove slow test case * Update docs for circular padding argument * Add images comparison for circular padding
huggingface#4025) * Add circular padding option * Fix style with black * Fix corner case with small image size * Add circular padding test cases * Fix docstring * Improve docstring for circular padding, remove slow test case * Update docs for circular padding argument * Add images comparison for circular padding
huggingface#4025) * Add circular padding option * Fix style with black * Fix corner case with small image size * Add circular padding test cases * Fix docstring * Improve docstring for circular padding, remove slow test case * Update docs for circular padding argument * Add images comparison for circular padding
Artifact-Free Panorama Generation with circular padding
This pull request addresses the issue mentioned in #4024. The proposed solution aims to achieve artifact-free panorama generation by seamlessly aligning the content on the left and right sides of the generated image, creating a proper “panorama”, viewable in 360 panoramas viewers.
In the existing MultiDiffusion approach, the image is cropped from left to right with a specified stride. To enable circular padding and support the desired 360-degree scenario, this PR introduces additional crops after the rightmost point of the image. Circular padding allows the model to “see” the transition from the rightmost part of the image to the leftmost part, maintaining consistency in 360-sense.
Furthermore, modifications are made to the decoding of latents in the case of StableDiffusion. Without these modifications, the decoded latents would not match in the RGB space, even if they align well in the latent space. Thus, the decoding of latents also incorporates circular padding to ensure consistent results.
A panorama image generated without circular padding:
A panorama image generated with circular padding:
To maintain backward compatibility and preserve the previous behaviour, the proposed circular padding functionality is implemented as an optional argument “circular_padding”, which is set to False by default.
Usage example: