-
Couldn't load subscription status.
- Fork 6.4k
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
yiyixuxu
merged 23 commits into
huggingface:main
from
raulc0399:main_pixart_alpha_controlnet
Oct 28, 2024
Merged
Changes from 15 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 abcc770
import structure for the pixart alpha controlnet pipeline
raulc0399 eaa2e21
use PixArtImageProcessor
raulc0399 3e2ec9a
moved the pixart controlnet in examples
raulc0399 98f63fb
rollback changes
raulc0399 e381b40
training script
raulc0399 2e6ca8c
moved pipepile to comunity folder
raulc0399 a6ed8f7
readme section for the pixart controlnet model and pipeline
raulc0399 908f615
Merge branch 'main' of https://github.com/huggingface/diffusers into …
raulc0399 531edde
Merge branch 'main' into main_pixart_alpha_controlnet
yiyixuxu 8c343e2
Merge branch 'main' into main_pixart_alpha_controlnet
yiyixuxu aed7d3d
Merge remote-tracking branch 'src/main' into main_pixart_alpha_contro…
raulc0399 510a102
Merge branch 'main_pixart_alpha_controlnet' of github.com:raulc0399/d…
raulc0399 0d1ed9d
moved the pixart controlnet pipeline under research_projects
raulc0399 d7f03f9
Merge branch 'main' into main_pixart_alpha_controlnet
sayakpaul 9b89559
make style && make quality;
lawrence-cj 5957191
make style && make quality;
lawrence-cj 995a79f
make style && make quality;
lawrence-cj 146dec2
moved the file to research_projects folder
raulc0399 236e81d
Merge branch 'main_pixart_alpha_controlnet' of github.com:raulc0399/d…
raulc0399 50679b3
Merge remote-tracking branch 'tmp/main_pixart_alpha_controlnet' into …
lawrence-cj 8bc5599
Merge remote-tracking branch 'src/main' into main_pixart_alpha_contro…
raulc0399 e3c5c05
Merge remote-tracking branch 'refs/remotes/tmp/main_pixart_alpha_cont…
lawrence-cj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
examples/community/run_pixart_alpha_controlnet_pipeline.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| 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 = "cinematic photo of superman in action . 35mm photograph, film, bokeh, professional, 4k, highly detailed" | ||
| # prompt = "yellow modern car, city in background, beautiful rainy day" | ||
| # prompt = "modern villa, clear sky, suny day . 35mm photograph, film, bokeh, professional, 4k, highly detailed" | ||
| # prompt = "robot dog toy in park . 35mm photograph, film, bokeh, professional, 4k, highly detailed" | ||
| # prompt = "purple car, on highway, beautiful sunny day" | ||
| # prompt = "realistical photo of a loving couple standing in the open kitchen of the living room, cooking ." | ||
| 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") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| images/ | ||
| output/ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this should go into README https://github.com/huggingface/diffusers/blob/main/examples/community/README.md
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.
i have added the section
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.
this file should not be here, no? should be in the same folder as others?
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.
just moved it