Skip to content

adds the pipeline for pixart alpha controlnet #8857

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

Merged
merged 23 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5389c8c
add the controlnet pipeline for pixart alpha
raulc0399 Jul 12, 2024
abcc770
import structure for the pixart alpha controlnet pipeline
raulc0399 Jul 12, 2024
eaa2e21
use PixArtImageProcessor
raulc0399 Jul 12, 2024
3e2ec9a
moved the pixart controlnet in examples
raulc0399 Jul 22, 2024
98f63fb
rollback changes
raulc0399 Jul 22, 2024
e381b40
training script
raulc0399 Jul 22, 2024
2e6ca8c
moved pipepile to comunity folder
raulc0399 Jul 23, 2024
a6ed8f7
readme section for the pixart controlnet model and pipeline
raulc0399 Jul 24, 2024
908f615
Merge branch 'main' of https://github.com/huggingface/diffusers into …
raulc0399 Sep 16, 2024
531edde
Merge branch 'main' into main_pixart_alpha_controlnet
yiyixuxu Sep 17, 2024
8c343e2
Merge branch 'main' into main_pixart_alpha_controlnet
yiyixuxu Sep 17, 2024
aed7d3d
Merge remote-tracking branch 'src/main' into main_pixart_alpha_contro…
raulc0399 Oct 16, 2024
510a102
Merge branch 'main_pixart_alpha_controlnet' of github.com:raulc0399/d…
raulc0399 Oct 16, 2024
0d1ed9d
moved the pixart controlnet pipeline under research_projects
raulc0399 Oct 16, 2024
d7f03f9
Merge branch 'main' into main_pixart_alpha_controlnet
sayakpaul Oct 18, 2024
9b89559
make style && make quality;
lawrence-cj Oct 25, 2024
5957191
make style && make quality;
lawrence-cj Oct 25, 2024
995a79f
make style && make quality;
lawrence-cj Oct 25, 2024
146dec2
moved the file to research_projects folder
raulc0399 Oct 27, 2024
236e81d
Merge branch 'main_pixart_alpha_controlnet' of github.com:raulc0399/d…
raulc0399 Oct 27, 2024
50679b3
Merge remote-tracking branch 'tmp/main_pixart_alpha_controlnet' into …
lawrence-cj Oct 27, 2024
8bc5599
Merge remote-tracking branch 'src/main' into main_pixart_alpha_contro…
raulc0399 Oct 27, 2024
e3c5c05
Merge remote-tracking branch 'refs/remotes/tmp/main_pixart_alpha_cont…
lawrence-cj Oct 28, 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
92 changes: 92 additions & 0 deletions examples/community/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Please also check out our [Community Scripts](https://github.com/huggingface/dif
| Stable Diffusion BoxDiff Pipeline | Training-free controlled generation with bounding boxes using [BoxDiff](https://github.com/showlab/BoxDiff) | [Stable Diffusion BoxDiff Pipeline](#stable-diffusion-boxdiff) | - | [Jingyang Zhang](https://github.com/zjysteven/) |
| FRESCO V2V Pipeline | Implementation of [[CVPR 2024] FRESCO: Spatial-Temporal Correspondence for Zero-Shot Video Translation](https://arxiv.org/abs/2403.12962) | [FRESCO V2V Pipeline](#fresco) | - | [Yifan Zhou](https://github.com/SingleZombie) |
| AnimateDiff IPEX Pipeline | Accelerate AnimateDiff inference pipeline with BF16/FP32 precision on Intel Xeon CPUs with [IPEX](https://github.com/intel/intel-extension-for-pytorch) | [AnimateDiff on IPEX](#animatediff-on-ipex) | - | [Dan Li](https://github.com/ustcuna/) |
PIXART-α Controlnet pipeline | Implementation of the controlnet model for pixart alpha and its diffusers pipeline | [PIXART-α Controlnet pipeline](#pixart-α-controlnet-pipeline) | - | [Raul Ciotescu](https://github.com/raulc0399/) |
| HunyuanDiT Differential Diffusion Pipeline | Applies [Differential Diffusion](https://github.com/exx8/differential-diffusion) to [HunyuanDiT](https://github.com/huggingface/diffusers/pull/8240). | [HunyuanDiT with Differential Diffusion](#hunyuandit-with-differential-diffusion) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1v44a5fpzyr4Ffr4v2XBQ7BajzG874N4P?usp=sharing) | [Monjoy Choudhury](https://github.com/MnCSSJ4x) |
| [🪆Matryoshka Diffusion Models](https://huggingface.co/papers/2310.15111) | A diffusion process that denoises inputs at multiple resolutions jointly and uses a NestedUNet architecture where features and parameters for small scale inputs are nested within those of the large scales. See [original codebase](https://github.com/apple/ml-mdm). | [🪆Matryoshka Diffusion Models](#matryoshka-diffusion-models) | [![Hugging Face Space](https://img.shields.io/badge/🤗%20Hugging%20Face-Space-yellow)](https://huggingface.co/spaces/pcuenq/mdm) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/gist/tolgacangoz/1f54875fc7aeaabcf284ebde64820966/matryoshka_hf.ipynb) | [M. Tolga Cangöz](https://github.com/tolgacangoz) |

Expand Down Expand Up @@ -4445,3 +4446,94 @@ grid_image.save(grid_dir + "sample.png")
`pag_scale` : guidance scale of PAG (ex: 5.0)

`pag_applied_layers_index` : index of the layer to apply perturbation (ex: ['m0'])

# PIXART-α Controlnet pipeline

[Project](https://pixart-alpha.github.io/) / [GitHub](https://github.com/PixArt-alpha/PixArt-alpha/blob/master/asset/docs/pixart_controlnet.md)

This the implementation of the controlnet model and the pipelne for the Pixart-alpha model, adapted to use the HuggingFace Diffusers.

## Example Usage

This example uses the Pixart HED Controlnet model, converted from the control net model as trained by the authors of the paper.

```py
import sys
import os
import torch
import torchvision.transforms as T
import torchvision.transforms.functional as TF

from pipeline_pixart_alpha_controlnet import PixArtAlphaControlnetPipeline
from diffusers.utils import load_image

from diffusers.image_processor import PixArtImageProcessor

from controlnet_aux import HEDdetector

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from pixart.controlnet_pixart_alpha import PixArtControlNetAdapterModel

controlnet_repo_id = "raulc0399/pixart-alpha-hed-controlnet"

weight_dtype = torch.float16
image_size = 1024

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

torch.manual_seed(0)

# load controlnet
controlnet = PixArtControlNetAdapterModel.from_pretrained(
controlnet_repo_id,
torch_dtype=weight_dtype,
use_safetensors=True,
).to(device)

pipe = PixArtAlphaControlnetPipeline.from_pretrained(
"PixArt-alpha/PixArt-XL-2-1024-MS",
controlnet=controlnet,
torch_dtype=weight_dtype,
use_safetensors=True,
).to(device)

images_path = "images"
control_image_file = "0_7.jpg"

prompt = "battleship in space, galaxy in background"

control_image_name = control_image_file.split('.')[0]

control_image = load_image(f"{images_path}/{control_image_file}")
print(control_image.size)
height, width = control_image.size

hed = HEDdetector.from_pretrained("lllyasviel/Annotators")

condition_transform = T.Compose([
T.Lambda(lambda img: img.convert('RGB')),
T.CenterCrop([image_size, image_size]),
])

control_image = condition_transform(control_image)
hed_edge = hed(control_image, detect_resolution=image_size, image_resolution=image_size)

hed_edge.save(f"{images_path}/{control_image_name}_hed.jpg")

# run pipeline
with torch.no_grad():
out = pipe(
prompt=prompt,
image=hed_edge,
num_inference_steps=14,
guidance_scale=4.5,
height=image_size,
width=image_size,
)

out.images[0].save(f"{images_path}//{control_image_name}_output.jpg")

```

In the folder examples/pixart there is also a script that can be used to train new models.
Please check the script `train_controlnet_hf_diffusers.sh` on how to start the training.
2 changes: 2 additions & 0 deletions examples/research_projects/pixart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
images/
output/
Loading
Loading