NightRaven109 commited on
Commit
41d3c82
Β·
verified Β·
1 Parent(s): 4445e78

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +10 -291
README.md CHANGED
@@ -1,291 +1,10 @@
1
- <p align="center">
2
- <img src="figs/logo.png" width="400">
3
- </p>
4
-
5
- <div align="center">
6
- <h2>Improving the Stability and Efficiency of Diffusion Models for Content Consistent Super-Resolution</h2>
7
-
8
-
9
- <a href='https://arxiv.org/pdf/2401.00877'><img src='https://img.shields.io/badge/Paper-Arxiv-red'></a>
10
-
11
-
12
- [Lingchen Sun](https://scholar.google.com/citations?hl=zh-CN&tzom=-480&user=ZCDjTn8AAAAJ)<sup>1,2</sup>
13
- | [Rongyuan Wu](https://scholar.google.com/citations?user=A-U8zE8AAAAJ&hl=zh-CN)<sup>1,2</sup> |
14
- [Jie Liang](https://scholar.google.com.sg/citations?user=REWxLZsAAAAJ&hl)<sup>2</sup> |
15
- [Zhengqiang Zhang](https://scholar.google.com/citations?hl=zh-CN&user=UX26wSMAAAAJ&view_op=list_works&sortby=pubdate)<sup>1,2</sup> |
16
- [Hongwei Yong](https://scholar.google.com.hk/citations?user=Xii74qQAAAAJ&hl=zh-CN)<sup>1</sup> |
17
- [Lei Zhang](https://www4.comp.polyu.edu.hk/~cslzhang)<sup>1,2</sup>
18
-
19
- <sup>1</sup>The Hong Kong Polytechnic University, <sup>2</sup>OPPO Research Institute
20
- </div>
21
-
22
- :star: If CCSR is helpful to your images or projects, please help star this repo. Thanks! :hugs:
23
-
24
- ## πŸ§‘ΰΎ€ΰ½² What's New in CCSR-v2?
25
- We have implemented the CCSR-v2 code based on the [Diffusers](https://github.com/huggingface/diffusers). Compared to CCSR-v1, CCSR-v2 brings a host of upgrades:
26
-
27
- - πŸ› οΈ**Step Flexibility**: Offers flexibility in diffusion step selection, **allowing users to freely adjust the number of steps to suit their specific requirements**. This adaptability **requires no additional re-training**, ensuring seamless integration into diverse workflows.
28
- - ⚑**Efficiency**: Supports highly efficient inference with **as few as 2 or even 1 diffusion step**, drastically reducing computation time without compromising quality.
29
- - πŸ“ˆ**Enhanced Clarity**: With upgraded algorithms, CCSR-v2 restores images with crisper details while maintaining fidelity.
30
- - βš–οΈ**Results stability**: CCSR-v2 exhibits significantly improved stability in synthesizing fine image details, ensuring higher-quality outputs.
31
- - πŸ”„**Stage 2 Refinement**: In CCSR-v2, the output $\hat{x}_{0 \gets T}$ from Stage 1 is now directly fed into Stage 2, streamlining the restoration process into an efficient one-step diffusion workflow. This strategy boosts both speed and performance.
32
-
33
- ![ccsr](figs/fig.png)
34
- Visual comparisons between the SR outputs with the same input low-quality image but two different noise samples by different DM-based
35
- methods. `S` denotes diffusion sampling timesteps. Existing DM-based methods, including StableSR, PASD, SeeSR, SUPIR and AddSR, **show noticeable instability with the different noise samples**. OSEDiff directly takes low-quality image as input without
36
- noise sampling. It is deterministic and stable, but **cannot perform multi-step diffusion** for high generative capacity. In contrast, **our proposed CCSR method
37
- is flexible for both multi-step diffusion and single-step diffusion, while producing stable results with high fidelity and visual quality**.
38
-
39
- ## ⏰ Update
40
- - **2024.12.12**: Code and models for CCSR-v2 are released. πŸ‘€ Please refer to this [branch](https://github.com/csslc/CCSR/tree/CCSR-v2.0).
41
- - **2024.9.25**: ⭐[CCSR-v2](https://arxiv.org/pdf/2401.00877) is released, offering reduced step requirements and supporting flexible diffusion step selection (2 or even 1 step) during the inference stage without the need for re-training.
42
- - **2023.12.23**: Code and models for [CCSR-v1](https://arxiv.org/pdf/2401.00877v1) are released. Please refer to this [branch](https://github.com/csslc/CCSR/tree/CCSR-v1.0).
43
-
44
-
45
- ## 🌟 Overview Framework
46
- ![ccsr](figs/framework.png)
47
-
48
- ## 😍 Visual Results
49
- ### Demo on Real-world SR
50
-
51
- [<img src="figs/compare_1.png" height="213px"/>](https://imgsli.com/MzI2MTg5) [<img src="figs/compare_2.png" height="213px"/>](https://imgsli.com/MzI2MTky/1/3) [<img src="figs/compare_3.png" height="213px"/>](https://imgsli.com/MzI2MTk0/0/2) [<img src="figs/compare_4.png" height="213px"/>](https://imgsli.com/MzI2MTk1/0/2)
52
-
53
-
54
- ![ccsr](figs/compare_standard.png)
55
-
56
- ![ccsr](figs/compare_efficient.png)
57
- For more comparisons, please refer to our paper for details.
58
-
59
- ## πŸ“ Quantitative comparisons
60
- We propose new stability metrics, namely global standard deviation (G-STD) and local standard deviation (L-STD), to respectively measure the image-level and pixel-level variations of the SR results of diffusion-based methods.
61
-
62
- More details about G-STD and L-STD can be found in our paper.
63
-
64
- ![ccsr](figs/table.png)
65
- ## βš™ Dependencies and Installation
66
- ```shell
67
- ## git clone this repository
68
- git clone https://github.com/csslc/CCSR.git
69
- cd CCSR
70
-
71
-
72
- # create an environment with python >= 3.9
73
- conda create -n ccsr python=3.9
74
- conda activate ccsr
75
- pip install -r requirements.txt
76
- ```
77
- ## 🍭 Quick Inference
78
- **For ease of comparison, we have provided the test results of CCSR-v2 on the DIV2K, RealSR, and DrealSR benchmarks with varying diffusion steps, which can be accessed via [Google Drive](https://drive.google.com/drive/folders/1xjURQZgKAlENzMnAJA2PDG9h_UxfZzio?usp=sharing).**
79
-
80
- #### Step 1: Download the pretrained models
81
- - Download the pretrained SD-2.1-base models from [HuggingFace](https://huggingface.co/stabilityai/stable-diffusion-2-1-base).
82
- - Download the CCSR-v2 models from and put the models in the `preset/models`:
83
-
84
- | Model Name | Description | GoogleDrive | BaiduNetdisk |
85
- |:-----------------------|:---------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------|
86
- | Controlnet | Trained in the stage 1. | [download](https://drive.google.com/drive/folders/1aHwgodKwKYZJBKs0QlFzanSjMDhrNyRA?usp=sharing) | [download](https://pan.baidu.com/s/1SKS70iE4GhhHGxqY1KS8mw) (pwd: ccsr) |
87
- | VAE | Trained in the stage 2. | [download](https://drive.google.com/drive/folders/1yHfMV81Md6db4StHTP5MC-eSeLFeBKm8?usp=sharing) | [download](https://pan.baidu.com/s/1fxOIeL6Hk6Muq9h8itAIKQ) (pwd: ccsr) |
88
- | Pre-trained Controlnet | The pre-trained model of stage1. | [download](https://drive.google.com/drive/folders/1LTtBRuObITOJwbW-sTDnHtp8xIUZFDHh?usp=sharing) | [download](https://pan.baidu.com/s/1mDeuHBqNj_Iol7PCY_Xfww) (pwd: ccsr) |
89
- | Dino models | The pre-trained models for disc. | [download](https://drive.google.com/drive/folders/1PcuZGUTJlltdPz2yk2ZIa4GCtb1yk_y6?usp=sharing) | [download](https://pan.baidu.com/s/1nPdNwgua91mDDRApWUm39Q) (pwd: ccsr) |
90
-
91
- #### Step 2: Prepare testing data
92
- You can put the testing images in the `preset/test_datasets`.
93
-
94
- #### Step 3: Running testing command
95
- For one-step diffusion process:
96
- ```
97
- python test_ccsr_tile.py \
98
- --pretrained_model_path preset/models/stable-diffusion-2-1-base \
99
- --controlnet_model_path preset/models \
100
- --vae_model_path preset/models \
101
- --baseline_name ccsr-v2 \
102
- --image_path preset/test_datasets \
103
- --output_dir experiments/test \
104
- --sample_method ddpm \
105
- --num_inference_steps 1 \
106
- --t_min 0.0 \
107
- --start_point lr \
108
- --start_steps 999 \
109
- --process_size 512 \
110
- --guidance_scale 1.0 \
111
- --sample_times 1 \
112
- --use_vae_encode_condition \
113
- --upscale 4
114
- ```
115
- For multi-step diffusion process:
116
- ```
117
- python test_ccsr_tile.py \
118
- --pretrained_model_path preset/models/stable-diffusion-2-1-base \
119
- --controlnet_model_path preset/models \
120
- --vae_model_path preset/models \
121
- --baseline_name ccsr-v2 \
122
- --image_path preset/test_datasets \
123
- --output_dir experiments/test \
124
- --sample_method ddpm \
125
- --num_inference_steps 6 \
126
- --t_max 0.6667 \
127
- --t_min 0.5 \
128
- --start_point lr \
129
- --start_steps 999 \
130
- --process_size 512 \
131
- --guidance_scale 4.5 \
132
- --sample_times 1 \
133
- --use_vae_encode_condition \
134
- --upscale 4
135
- ```
136
- We integrate [tile_diffusion](https://github.com/albarji/mixture-of-diffusers) and [tile_vae](https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111/tree/main) to the [test_ccsr_tile.py](test_ccsr_tile.py) to save the GPU memory for inference.
137
- You can change the tile size and stride according to the VRAM of your device.
138
- ```
139
- python test_ccsr_tile.py \
140
- --pretrained_model_path preset/models/stable-diffusion-2-1-base \
141
- --controlnet_model_path preset/models \
142
- --vae_model_path preset/models \
143
- --baseline_name ccsr-v2 \
144
- --image_path preset/test_datasets \
145
- --output_dir experiments/test \
146
- --sample_method ddpm \
147
- --num_inference_steps 6 \
148
- --t_max 0.6667 \
149
- --t_min 0.5 \
150
- --start_point lr \
151
- --start_steps 999 \
152
- --process_size 512 \
153
- --guidance_scale 4.5 \
154
- --sample_times 1 \
155
- --use_vae_encode_condition \
156
- --upscale 4 \
157
- --tile_diffusion \
158
- --tile_diffusion_size 512 \
159
- --tile_diffusion_stride 256 \
160
- --tile_vae \
161
- --vae_decoder_tile_size 224 \
162
- --vae_encoder_tile_size 1024 \
163
- ```
164
-
165
- You can obtain `N` different SR results by setting `sample_times` as `N` to test the stability of CCSR. The data folder should be like this:
166
-
167
- ```
168
- experiments/test
169
- β”œβ”€β”€ sample00 # the first group of SR results
170
- └── sample01 # the second group of SR results
171
- ...
172
- └── sampleN # the N-th group of SR results
173
- ```
174
-
175
- ## πŸ“ Evaluation
176
- 1. Calculate the Image Quality Assessment for each restored group.
177
-
178
- Fill in the required information in [cal_iqa.py](cal_iqa/cal_iqa.py) and run, then you can obtain the evaluation results in the folder like this:
179
- ```
180
- log_path
181
- β”œβ”€β”€ log_name_npy # save the IQA values of each restored group as the npy files
182
- └── log_name.log # log recode
183
- ```
184
-
185
- 2. Calculate the G-STD value for the diffusion-based SR method.
186
-
187
- Fill in the required information in [iqa_G-STD.py](cal_iqa/iqa_G-STD.py) and run, then you can obtain the mean IQA values of N restored groups and G-STD value.
188
-
189
- 3. Calculate the L-STD value for the diffusion-based SR method.
190
-
191
- Fill in the required information in [iqa_L-STD.py](cal_iqa/iqa_L-STD.py) and run, then you can obtain the L-STD value.
192
-
193
-
194
- ## πŸš‹ Train
195
-
196
- #### Step1: Prepare training data
197
- Generate txt file for the training set.
198
- Fill in the required information in [get_path](scripts/get_path.py) and run, then you can obtain the txt file recording the paths of ground-truth images.
199
- You can save the txt file into `preset/gt_path.txt`.
200
-
201
- #### Step2: Train Stage1 Model
202
- 1. Download pretrained [Stable Diffusion v2.1](https://huggingface.co/stabilityai/stable-diffusion-2-1-base) to provide generative capabilities.
203
-
204
- ```shell
205
- wget https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-ema-pruned.ckpt --no-check-certificate
206
- ```
207
-
208
- 2. Start training.
209
-
210
- ```shell
211
- CUDA_VISIBLE_DEVICES="0,1,2,3," accelerate launch train_ccsr_stage1.py \
212
- --pretrained_model_name_or_path="preset/models/stable-diffusion-2-1-base" \
213
- --controlnet_model_name_or_path='preset/models/pretrained_controlnet' \
214
- --enable_xformers_memory_efficient_attention \
215
- --output_dir="./experiments/ccsrv2_stage1" \
216
- --mixed_precision="fp16" \
217
- --resolution=512 \
218
- --learning_rate=5e-5 \
219
- --train_batch_size=4 \
220
- --gradient_accumulation_steps=6 \
221
- --dataloader_num_workers=0 \
222
- --checkpointing_steps=500 \
223
- --t_max=0.6667 \
224
- --max_train_steps=20000 \
225
- --dataset_root_folders 'preset/gt_path.txt'
226
- ```
227
-
228
- #### Step3: Train Stage2 Model
229
- 1. Put the model obtained from the stage1 into `controlnet_model_name_or_path`.
230
- 2. Start training.
231
- ```shell
232
- CUDA_VISIBLE_DEVICES="0,1,2,3," accelerate launch train_ccsr_stage2.py \
233
- --pretrained_model_name_or_path="preset/models/stable-diffusion-2-1-base" \
234
- --controlnet_model_name_or_path='preset/models/model_stage1' \
235
- --enable_xformers_memory_efficient_attention \
236
- --output_dir="./experiments/ccsrv2_stage2" \
237
- --mixed_precision="fp16" \
238
- --resolution=512 \
239
- --learning_rate=5e-6 \
240
- --train_batch_size=2 \
241
- --gradient_accumulation_steps=8 \
242
- --checkpointing_steps=500 \
243
- --is_start_lr=True \
244
- --t_max=0.6667 \
245
- --num_inference_steps=1 \
246
- --is_module \
247
- --lambda_l2=1.0 \
248
- --lambda_lpips=1.0 \
249
- --lambda_disc=0.05 \
250
- --lambda_disc_train=0.5 \
251
- --begin_disc=100 \
252
- --max_train_steps=2000 \
253
- --dataset_root_folders 'preset/gt_path.txt'
254
- ```
255
-
256
-
257
-
258
-
259
-
260
- ### Citations
261
-
262
- If our code helps your research or work, please consider citing our paper.
263
- The following are BibTeX references:
264
-
265
- ```
266
- @article{sun2023ccsr,
267
- title={Improving the Stability of Diffusion Models for Content Consistent Super-Resolution},
268
- author={Sun, Lingchen and Wu, Rongyuan and Zhang, Zhengqiang and Yong, Hongwei and Zhang, Lei},
269
- journal={arXiv preprint arXiv:2401.00877},
270
- year={2024}
271
- }
272
- ```
273
-
274
- ### License
275
- This project is released under the [Apache 2.0 license](LICENSE).
276
-
277
- ### Acknowledgement
278
- This project is based on [ControlNet](https://github.com/lllyasviel/ControlNet), [BasicSR](https://github.com/XPixelGroup/BasicSR) and [SeeSR](https://github.com/cswry/SeeSR). Some codes are brought from [ADDSR](https://github.com/NJU-PCALab/AddSR). Thanks for their awesome works.
279
-
280
- ### Contact
281
- If you have any questions, please contact: [email protected]
282
-
283
-
284
- <details>
285
- <summary>statistics</summary>
286
-
287
- ![visitors](https://visitor-badge.laobi.icu/badge?page_id=csslc/CCSR)
288
-
289
- </details>
290
-
291
-
 
1
+ ---
2
+ title: TextureUpscaleBeta
3
+ emoji: 🏒
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 5.9.1
8
+ app_file: app.py
9
+ pinned: false
10
+ ---