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

[Community] PromptDiffusion Pipeline #6752

Merged
merged 30 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
74bf30f
Create promptdiffusioncontrolnet.py
iczaw Jan 25, 2024
57943e5
Update __init__.py
iczaw Jan 25, 2024
eb47987
Update __init__.py
iczaw Jan 25, 2024
d238058
Update promptdiffusioncontrolnet.py
iczaw Jan 25, 2024
60c5266
Create pipeline_prompt_diffusion.py
iczaw Jan 25, 2024
887bb28
Create convert_original_promptdiffusion_to_diffusers.py
iczaw Jan 25, 2024
fd0ef1c
Update convert_from_ckpt.py
iczaw Jan 25, 2024
321ec2d
Update promptdiffusioncontrolnet.py
iczaw Jan 29, 2024
5a04a26
Update pipeline_prompt_diffusion.py
iczaw Jan 29, 2024
3b95ff6
Update README.md
iczaw Jan 29, 2024
a3444eb
Update pipeline_prompt_diffusion.py
iczaw Jan 29, 2024
daa5490
Delete src/diffusers/models/promptdiffusioncontrolnet.py
iczaw Feb 4, 2024
edda2a8
Update __init__.py
iczaw Feb 4, 2024
9fa8d48
Update __init__.py
iczaw Feb 4, 2024
b8fcc55
Delete scripts/convert_original_promptdiffusion_to_diffusers.py
iczaw Feb 4, 2024
288aabe
Update convert_from_ckpt.py
iczaw Feb 4, 2024
a20b904
Update README.md
iczaw Feb 4, 2024
9f3534b
Delete examples/community/pipeline_prompt_diffusion.py
iczaw Feb 4, 2024
0640e06
Create README.md
iczaw Feb 4, 2024
9722e28
Create promptdiffusioncontrolnet.py
iczaw Feb 4, 2024
1d463c8
Create convert_original_promptdiffusion_to_diffusers.py
iczaw Feb 4, 2024
0ba43f8
Create pipeline_prompt_diffusion.py
iczaw Feb 4, 2024
22f79a2
Update README.md
iczaw Feb 6, 2024
c545c6c
Update pipeline_prompt_diffusion.py
iczaw Feb 6, 2024
d9d63ef
Update README.md
iczaw Feb 8, 2024
1ebbaf6
Update pipeline_prompt_diffusion.py
iczaw Feb 8, 2024
b81a23e
Update convert_original_promptdiffusion_to_diffusers.py
iczaw Feb 8, 2024
0ec85a7
Update promptdiffusioncontrolnet.py
iczaw Feb 8, 2024
b6260af
Update README.md
iczaw Mar 4, 2024
c35b571
Merge branch 'main' into prompt-diffusion
sayakpaul Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions examples/research_projects/promptdiffusion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# PromptDiffusion Pipeline

From the project [page](https://zhendong-wang.github.io/prompt-diffusion.github.io/)

"With a prompt consisting of a task-specific example pair of images and text guidance, and a new query image, Prompt Diffusion can comprehend the desired task and generate the corresponding output image on both seen (trained) and unseen (new) task types."

For any usage questions, please refer to the [paper](https://arxiv.org/abs/2305.01115).

Prepare models by converting them from the [checkpoint](https://huggingface.co/zhendongw/prompt-diffusion)

To convert the controlnet, use cldm_v15.yaml from the [repository](https://github.com/Zhendong-Wang/Prompt-Diffusion/tree/main/models/):

```bash
python convert_original_promptdiffusion_to_diffusers.py --checkpoint_path path-to-network-step04999.ckpt --original_config_file path-to-cldm_v15.yaml --dump_path path-to-output-directory
```

To learn about how to convert the fine-tuned stable diffusion model, see the [Load different Stable Diffusion formats guide](https://huggingface.co/docs/diffusers/main/en/using-diffusers/other-formats).


```py
import torch
from diffusers import UniPCMultistepScheduler
from diffusers.utils import load_image
from promptdiffusioncontrolnet import PromptDiffusionControlNetModel
from pipeline_prompt_diffusion import PromptDiffusionPipeline


from PIL import ImageOps

image_a = ImageOps.invert(load_image("https://github.com/Zhendong-Wang/Prompt-Diffusion/blob/main/images_to_try/house_line.png?raw=true"))

image_b = load_image("https://github.com/Zhendong-Wang/Prompt-Diffusion/blob/main/images_to_try/house.png?raw=true")
query = ImageOps.invert(load_image("https://github.com/Zhendong-Wang/Prompt-Diffusion/blob/main/images_to_try/new_01.png?raw=true"))

# load prompt diffusion controlnet and prompt diffusion

controlnet = PromptDiffusionControlNetModel.from_pretrained("iczaw/prompt-diffusion-diffusers", subfolder="controlnet", torch_dtype=torch.float16)
model_id = "path-to-model"
pipe = PromptDiffusionPipeline.from_pretrained("iczaw/prompt-diffusion-diffusers", subfolder="base", controlnet=controlnet, torch_dtype=torch.float16, variant="fp16")

# speed up diffusion process with faster scheduler and memory optimization
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
# remove following line if xformers is not installed
pipe.enable_xformers_memory_efficient_attention()
pipe.enable_model_cpu_offload()
# generate image
generator = torch.manual_seed(0)
image = pipe("a tortoise", num_inference_steps=20, generator=generator, image_pair=[image_a,image_b], image=query).images[0]

```
Loading
Loading