Views
No views yet

| Control Condition | Control Image | Generated Image 1 | Generated Image 2 |
|---|---|---|---|
| canny | ![]() | ![]() | ![]() |
| depth | ![]() | ![]() | ![]() |
| lineart | ![]() | ![]() | ![]() |
| softedge | ![]() | ![]() | ![]() |
| normal | ![]() | ![]() | ![]() |
| openpose | ![]() | ![]() | ![]() |
git clone https://github.com/modelscope/DiffSynth-Studio.git
cd DiffSynth-Studio
pip install -e .1from PIL import Image
2import torch
3from modelscope import dataset_snapshot_download, snapshot_download
4from diffsynth.pipelines.qwen_image import QwenImagePipeline, ModelConfig
5from diffsynth.controlnets.processors import Annotator
6
7allow_file_pattern = ["sk_model.pth", "sk_model2.pth", "dpt_hybrid-midas-501f0c75.pt", "ControlNetHED.pth", "body_pose_model.pth", "hand_pose_model.pth", "facenet.pth", "scannet.pt"]
8snapshot_download("lllyasviel/Annotators", local_dir="models/Annotators", allow_file_pattern=allow_file_pattern)
9
10pipe = QwenImagePipeline.from_pretrained(
11 torch_dtype=torch.bfloat16,
12 device="cuda",
13 model_configs=[
14 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="transformer/diffusion_pytorch_model*.safetensors"),
15 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="text_encoder/model*.safetensors"),
16 ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="vae/diffusion_pytorch_model.safetensors"),
17 ],
18 tokenizer_config=ModelConfig(model_id="Qwen/Qwen-Image", origin_file_pattern="tokenizer/"),
19)
20snapshot_download("DiffSynth-Studio/Qwen-Image-In-Context-Control-Union", local_dir="models/DiffSynth-Studio/Qwen-Image-In-Context-Control-Union", allow_file_pattern="model.safetensors")
21pipe.load_lora(pipe.dit, "models/DiffSynth-Studio/Qwen-Image-In-Context-Control-Union/model.safetensors")
22
23dataset_snapshot_download(dataset_id="DiffSynth-Studio/examples_in_diffsynth", local_dir="./", allow_file_pattern=f"data/examples/qwen-image-context-control/image.jpg")
24origin_image = Image.open("data/examples/qwen-image-context-control/image.jpg").resize((1024, 1024))
25annotator_ids = ['openpose', 'canny', 'depth', 'lineart', 'softedge', 'normal']
26for annotator_id in annotator_ids:
27 annotator = Annotator(processor_id=annotator_id, device="cuda")
28 control_image = annotator(origin_image)
29 control_image.save(f"{annotator.processor_id}.png")
30
31 control_prompt = "Context_Control. "
32 prompt = f"{control_prompt}一A beautiful girl in light blue is dancing against a dreamy starry sky with interweaving light and shadow and exquisite details."
33 negative_prompt = "Mesh, regular grid, blurry, low resolution, low quality, distorted, deformed, wrong anatomy, distorted hands, distorted body, distorted face, distorted hair, distorted eyes, distorted mouth"
34 image = pipe(prompt, seed=1, negative_prompt=negative_prompt, context_image=control_image, height=1024, width=1024)
35 image.save(f"image_{annotator.processor_id}.png")