Skip to content

Commit

Permalink
Add ddim inversion pix2pix (open-mmlab#2397)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Feb 17, 2023
1 parent 01a8080 commit 14b9507
Show file tree
Hide file tree
Showing 11 changed files with 808 additions and 88 deletions.
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
title: Overview
- local: api/schedulers/ddim
title: DDIM
- local: api/schedulers/ddim_inverse
title: DDIMInverse
- local: api/schedulers/ddpm
title: DDPM
- local: api/schedulers/deis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ caption = pipeline.generate_caption(raw_image)
Then we employ the generated caption and the input image to get the inverted noise:

```py
inv_latents, inv_image = pipeline.invert(caption, image=raw_image)
generator = torch.manual_seed(0)
inv_latents = pipeline.invert(caption, image=raw_image, generator=generator).latents
```

Now, generate the image with edit directions:

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

Expand Down
21 changes: 21 additions & 0 deletions docs/source/en/api/schedulers/ddim_inverse.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--Copyright 2023 The HuggingFace Team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->

# Inverse Denoising Diffusion Implicit Models (DDIMInverse)

## Overview

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.
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)

## DDIMInverseScheduler
[[autodoc]] DDIMInverseScheduler
1 change: 1 addition & 0 deletions docs/source/en/api/schedulers/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following table summarizes all officially supported schedulers, their corres
| Scheduler | Paper |
|---|---|
| [ddim](./ddim) | [**Denoising Diffusion Implicit Models**](https://arxiv.org/abs/2010.02502) |
| [ddim_inverse](./ddim_inverse) | [**Denoising Diffusion Implicit Models**](https://arxiv.org/abs/2010.02502) |
| [ddpm](./ddpm) | [**Denoising Diffusion Probabilistic Models**](https://arxiv.org/abs/2006.11239) |
| [deis](./deis) | [**DEISMultistepScheduler**](https://arxiv.org/abs/2204.13902) |
| [singlestep_dpm_solver](./singlestep_dpm_solver) | [**Singlestep DPM-Solver**](https://arxiv.org/abs/2206.00927) |
Expand Down
1 change: 1 addition & 0 deletions src/diffusers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
ScoreSdeVePipeline,
)
from .schedulers import (
DDIMInverseScheduler,
DDIMScheduler,
DDPMScheduler,
DEISMultistepScheduler,
Expand Down
2 changes: 1 addition & 1 deletion src/diffusers/pipelines/pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def components(self) -> Dict[str, Any]:
if set(components.keys()) != expected_modules:
raise ValueError(
f"{self} has been incorrectly initialized or {self.__class__} is incorrectly implemented. Expected"
f" {expected_modules} to be defined, but {components} are defined."
f" {expected_modules} to be defined, but {components.keys()} are defined."
)

return components
Expand Down
Loading

0 comments on commit 14b9507

Please sign in to comment.