Image-to-Image
Diffusers
lc03lc commited on
Commit
eefcdfb
·
verified ·
1 Parent(s): 034aeeb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +151 -3
README.md CHANGED
@@ -1,3 +1,151 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: OmniConsistency
3
+ emoji: 🚀
4
+ colorFrom: gray
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 5.31.0
8
+ app_file: app.py
9
+ pinned: false
10
+ short_description: Generate styled image from reference image and external LoRA
11
+ license: mit
12
+ base_model:
13
+ - black-forest-labs/FLUX.1-dev
14
+ ---
15
+
16
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
17
+
18
+ > **OmniConsistency: Learning Style-Agnostic
19
+ Consistency from Paired Stylization Data**
20
+ > <br>
21
+ > [Yiren Song](https://scholar.google.com.hk/citations?user=L2YS0jgAAAAJ),
22
+ > [Cheng Liu](https://scholar.google.com.hk/citations?hl=zh-CN&user=TvdVuAYAAAAJ),
23
+ > and
24
+ > [Mike Zheng Shou](https://sites.google.com/view/showlab)
25
+ > <br>
26
+ > [Show Lab](https://sites.google.com/view/showlab), National University of Singapore
27
+ > <br>
28
+
29
+ <img src='./figure/teaser.png' width='100%' />
30
+
31
+ ## Installation
32
+
33
+ We recommend using Python 3.10 and PyTorch with CUDA support. To set up the environment:
34
+
35
+ ```bash
36
+ # Create a new conda environment
37
+ conda create -n omniconsistency python=3.10
38
+ conda activate omniconsistency
39
+
40
+ # Install other dependencies
41
+ pip install -r requirements.txt
42
+ ```
43
+
44
+ ## Download
45
+
46
+ You can download the OmniConsistency model and pretrained LoRAs directly from [Hugging Face](https://huggingface.co/showlab/OmniConsistency).
47
+ Or download using Python script:
48
+
49
+ ### OmniConsistency Model
50
+
51
+ ```python
52
+ from huggingface_hub import hf_hub_download
53
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/3D_Chibi_rank128_bf16.safetensors", local_dir="./LoRAs")
54
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/American_Cartoon_rank128_bf16.safetensors", local_dir="./LoRAs")
55
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Chinese_Ink_rank128_bf16.safetensors", local_dir="./LoRAs")
56
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Clay_Toy_rank128_bf16.safetensors", local_dir="./LoRAs")
57
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Fabric_rank128_bf16.safetensors", local_dir="./LoRAs")
58
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Ghibli_rank128_bf16.safetensors", local_dir="./LoRAs")
59
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Irasutoya_rank128_bf16.safetensors", local_dir="./LoRAs")
60
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Jojo_rank128_bf16.safetensors", local_dir="./LoRAs")
61
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/LEGO_rank128_bf16.safetensors", local_dir="./LoRAs")
62
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Line_rank128_bf16.safetensors", local_dir="./LoRAs")
63
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Macaron_rank128_bf16.safetensors", local_dir="./LoRAs")
64
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Oil_Painting_rank128_bf16.safetensors", local_dir="./LoRAs")
65
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Origami_rank128_bf16.safetensors", local_dir="./LoRAs")
66
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Paper_Cutting_rank128_bf16.safetensors", local_dir="./LoRAs")
67
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Picasso_rank128_bf16.safetensors", local_dir="./LoRAs")
68
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Pixel_rank128_bf16.safetensors", local_dir="./LoRAs")
69
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Poly_rank128_bf16.safetensors", local_dir="./LoRAs")
70
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Pop_Art_rank128_bf16.safetensors", local_dir="./LoRAs")
71
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Rick_Morty_rank128_bf16.safetensors", local_dir="./LoRAs")
72
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Snoopy_rank128_bf16.safetensors", local_dir="./LoRAs")
73
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Van_Gogh_rank128_bf16.safetensors", local_dir="./LoRAs")
74
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="LoRAs/Vector_rank128_bf16.safetensors", local_dir="./LoRAs")
75
+ ```
76
+ ### Pretrained LoRAs
77
+ ```python
78
+ from huggingface_hub import hf_hub_download
79
+ hf_hub_download(repo_id="showlab/OmniConsistency", filename="OmniConsistency.safetensors", local_dir="./Model")
80
+ ```
81
+
82
+ ## Usage
83
+ Here's a basic example of using OmniConsistency:
84
+
85
+ ### Model Initialization
86
+ ```python
87
+ import time
88
+ import torch
89
+ from PIL import Image
90
+ from src_inference.pipeline import FluxPipeline
91
+ from src_inference.lora_helper import set_single_lora
92
+
93
+ def clear_cache(transformer):
94
+ for name, attn_processor in transformer.attn_processors.items():
95
+ attn_processor.bank_kv.clear()
96
+
97
+ # Initialize model
98
+ device = "cuda"
99
+ base_path = "/path/to/black-forest-labs/FLUX.1-dev"
100
+ pipe = FluxPipeline.from_pretrained(base_path, torch_dtype=torch.bfloat16).to("cuda")
101
+
102
+ # Load OmniConsistency model
103
+ set_single_lora(pipe.transformer,
104
+ "/path/to/OmniConsistency.safetensors",
105
+ lora_weights=[1], cond_size=512)
106
+
107
+ # Load external LoRA
108
+ pipe.unload_lora_weights()
109
+ pipe.load_lora_weights("/path/to/lora_folder",
110
+ weight_name="lora_name.safetensors")
111
+ ```
112
+
113
+ ### Style Inference
114
+ ```python
115
+ image_path1 = "figure/test.png"
116
+ prompt = "3D Chibi style, Three individuals standing together in the office."
117
+
118
+ subject_images = []
119
+ spatial_image = [Image.open(image_path1).convert("RGB")]
120
+
121
+ width, height = 1024, 1024
122
+
123
+ start_time = time.time()
124
+
125
+ image = pipe(
126
+ prompt,
127
+ height=height,
128
+ width=width,
129
+ guidance_scale=3.5,
130
+ num_inference_steps=25,
131
+ max_sequence_length=512,
132
+ generator=torch.Generator("cpu").manual_seed(5),
133
+ spatial_images=spatial_image,
134
+ subject_images=subject_images,
135
+ cond_size=512,
136
+ ).images[0]
137
+
138
+ end_time = time.time()
139
+ elapsed_time = end_time - start_time
140
+ print(f"code running time: {elapsed_time} s")
141
+
142
+ # Clear cache after generation
143
+ clear_cache(pipe.transformer)
144
+
145
+ image.save("results/output.png")
146
+ ```
147
+
148
+ <!-- ## Citation
149
+ ```
150
+
151
+ ``` -->