Skip to content

Commit 14b9507

Browse files
patrickvonplatenpatil-surajpcuenca
authored
Add ddim inversion pix2pix (huggingface#2397)
* add * finish * add tests * add tests * up * up * pull from main * uP * Apply suggestions from code review * finish * Update docs/source/en/_toctree.yml Co-authored-by: Suraj Patil <[email protected]> * finish * clean docs * next * next * Apply suggestions from code review Co-authored-by: Pedro Cuenca <[email protected]> * up * up --------- Co-authored-by: Suraj Patil <[email protected]> Co-authored-by: Pedro Cuenca <[email protected]>
1 parent 01a8080 commit 14b9507

File tree

11 files changed

+808
-88
lines changed

11 files changed

+808
-88
lines changed

docs/source/en/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@
182182
title: Overview
183183
- local: api/schedulers/ddim
184184
title: DDIM
185+
- local: api/schedulers/ddim_inverse
186+
title: DDIMInverse
185187
- local: api/schedulers/ddpm
186188
title: DDPM
187189
- local: api/schedulers/deis

docs/source/en/api/pipelines/stable_diffusion/pix2pix_zero.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,15 @@ caption = pipeline.generate_caption(raw_image)
138138
Then we employ the generated caption and the input image to get the inverted noise:
139139

140140
```py
141-
inv_latents, inv_image = pipeline.invert(caption, image=raw_image)
141+
generator = torch.manual_seed(0)
142+
inv_latents = pipeline.invert(caption, image=raw_image, generator=generator).latents
142143
```
143144

144145
Now, generate the image with edit directions:
145146

146147
```py
147148
# See the "Generating source and target embeddings" section below to
148-
# automate the generation of these captions with a pre-trained model like Flan-T5.
149+
# automate the generation of these captions with a pre-trained model like Flan-T5 as explained below.
149150
source_prompts = ["a cat sitting on the street", "a cat playing in the field", "a face of a cat"]
150151
target_prompts = ["a dog sitting on the street", "a dog playing in the field", "a face of a dog"]
151152

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--Copyright 2023 The HuggingFace Team. All rights reserved.
2+
3+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4+
the License. You may obtain a copy of the License at
5+
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
-->
12+
13+
# Inverse Denoising Diffusion Implicit Models (DDIMInverse)
14+
15+
## Overview
16+
17+
This scheduler is the inverted scheduler of [Denoising Diffusion Implicit Models](https://arxiv.org/abs/2010.02502) (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon.
18+
The implementation is mostly based on the DDIM inversion definition of [Null-text Inversion for Editing Real Images using Guided Diffusion Models](https://arxiv.org/pdf/2211.09794.pdf)
19+
20+
## DDIMInverseScheduler
21+
[[autodoc]] DDIMInverseScheduler

docs/source/en/api/schedulers/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The following table summarizes all officially supported schedulers, their corres
4646
| Scheduler | Paper |
4747
|---|---|
4848
| [ddim](./ddim) | [**Denoising Diffusion Implicit Models**](https://arxiv.org/abs/2010.02502) |
49+
| [ddim_inverse](./ddim_inverse) | [**Denoising Diffusion Implicit Models**](https://arxiv.org/abs/2010.02502) |
4950
| [ddpm](./ddpm) | [**Denoising Diffusion Probabilistic Models**](https://arxiv.org/abs/2006.11239) |
5051
| [deis](./deis) | [**DEISMultistepScheduler**](https://arxiv.org/abs/2204.13902) |
5152
| [singlestep_dpm_solver](./singlestep_dpm_solver) | [**Singlestep DPM-Solver**](https://arxiv.org/abs/2206.00927) |

src/diffusers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
ScoreSdeVePipeline,
6868
)
6969
from .schedulers import (
70+
DDIMInverseScheduler,
7071
DDIMScheduler,
7172
DDPMScheduler,
7273
DEISMultistepScheduler,

src/diffusers/pipelines/pipeline_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def components(self) -> Dict[str, Any]:
929929
if set(components.keys()) != expected_modules:
930930
raise ValueError(
931931
f"{self} has been incorrectly initialized or {self.__class__} is incorrectly implemented. Expected"
932-
f" {expected_modules} to be defined, but {components} are defined."
932+
f" {expected_modules} to be defined, but {components.keys()} are defined."
933933
)
934934

935935
return components

0 commit comments

Comments
 (0)