eleasm wangkanai commited on
Commit
d9bad96
·
0 Parent(s):

Duplicate from wangkanai/flux-upscale

Browse files

Co-authored-by: wangkanai <wangkanai@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ library_name: realesrgan
4
+ pipeline_tag: image-to-image
5
+ tags:
6
+ - image-upscaling
7
+ - super-resolution
8
+ - realesrgan
9
+ - esrgan
10
+ - post-processing
11
+ - image-enhancement
12
+ ---
13
+
14
+ <!-- README Version: v1.3 -->
15
+
16
+ # FLUX Upscale Models Collection v1.3
17
+
18
+ This repository contains Real-ESRGAN upscale models for post-processing and enhancing generated images. These models can upscale images by 2x or 4x while adding fine details and improving sharpness.
19
+
20
+ ## Model Description
21
+
22
+ Real-ESRGAN (Real Enhanced Super-Resolution Generative Adversarial Networks) models for high-quality image upscaling. These models are commonly used as post-processing steps for AI-generated images to increase resolution and enhance details.
23
+
24
+ **Key Capabilities**:
25
+ - 2x and 4x image upscaling
26
+ - Detail enhancement and sharpening
27
+ - Noise reduction and artifact removal
28
+ - Optimized for AI-generated images
29
+ - CPU and GPU compatible
30
+
31
+ ## Repository Contents
32
+
33
+ **Total Size**: ~192MB
34
+
35
+ ### Upscale Models (upscale_models/)
36
+ - `4x-UltraSharp.pth` - 64MB - 4x upscaling with ultra-sharp detail enhancement
37
+ - `RealESRGAN-x2plus.pth` - 64MB - 2x upscaling model
38
+ - `RealESRGAN-x4plus.pth` - 64MB - 4x upscaling model
39
+
40
+ ## Hardware Requirements
41
+
42
+ - **VRAM**: 4GB+ recommended for GPU inference
43
+ - **Disk Space**: 192MB
44
+ - **Memory**: 8GB+ system RAM recommended
45
+ - **Compatible with**: CPU or GPU inference (CUDA, ROCm, or CPU)
46
+
47
+ ## Usage Examples
48
+
49
+ ### Basic Usage with Real-ESRGAN
50
+
51
+ ```python
52
+ from basicsr.archs.rrdbnet_arch import RRDBNet
53
+ from realesrgan import RealESRGANer
54
+ import cv2
55
+
56
+ # Load the upscaler model
57
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
58
+
59
+ upsampler = RealESRGANer(
60
+ scale=4,
61
+ model_path="E:\\huggingface\\flux-upscale\\upscale_models\\4x-UltraSharp.pth",
62
+ model=model,
63
+ tile=0,
64
+ tile_pad=10,
65
+ pre_pad=0,
66
+ half=True # Use FP16 for faster inference on GPU
67
+ )
68
+
69
+ # Load and upscale an image
70
+ img = cv2.imread("input.png", cv2.IMREAD_COLOR)
71
+ output, _ = upsampler.enhance(img, outscale=4)
72
+ cv2.imwrite("output_upscaled.png", output)
73
+ ```
74
+
75
+ ### Using with FLUX Pipeline
76
+
77
+ ```python
78
+ from diffusers import FluxPipeline
79
+ from realesrgan import RealESRGANer
80
+ from basicsr.archs.rrdbnet_arch import RRDBNet
81
+ import torch
82
+ import numpy as np
83
+
84
+ # Generate image with FLUX
85
+ pipe = FluxPipeline.from_pretrained(
86
+ "E:\\huggingface\\flux-dev-fp16",
87
+ torch_dtype=torch.float16
88
+ )
89
+ pipe.to("cuda")
90
+
91
+ image = pipe(
92
+ prompt="a beautiful landscape with mountains",
93
+ num_inference_steps=30
94
+ ).images[0]
95
+
96
+ # Convert PIL to numpy/cv2 format
97
+ img_array = np.array(image)
98
+
99
+ # Initialize upscaler
100
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
101
+ upsampler = RealESRGANer(
102
+ scale=4,
103
+ model_path="E:\\huggingface\\flux-upscale\\upscale_models\\4x-UltraSharp.pth",
104
+ model=model,
105
+ half=True
106
+ )
107
+
108
+ # Upscale the generated image
109
+ upscaled, _ = upsampler.enhance(img_array, outscale=4)
110
+
111
+ # Save result
112
+ import cv2
113
+ cv2.imwrite("flux_upscaled_4x.png", upscaled)
114
+ ```
115
+
116
+ ### Tiled Processing for Large Images
117
+
118
+ ```python
119
+ from basicsr.archs.rrdbnet_arch import RRDBNet
120
+ from realesrgan import RealESRGANer
121
+ import cv2
122
+
123
+ # Configure for large images with tiling
124
+ model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
125
+
126
+ upsampler = RealESRGANer(
127
+ scale=4,
128
+ model_path="E:\\huggingface\\flux-upscale\\upscale_models\\RealESRGAN_x4plus.pth",
129
+ model=model,
130
+ tile=512, # Process in 512x512 tiles
131
+ tile_pad=10, # Padding to avoid seams
132
+ pre_pad=0,
133
+ half=True
134
+ )
135
+
136
+ # Process large image
137
+ img = cv2.imread("large_image.png", cv2.IMREAD_COLOR)
138
+ output, _ = upsampler.enhance(img, outscale=4)
139
+ cv2.imwrite("large_upscaled.png", output)
140
+ ```
141
+
142
+ ## Model Comparison
143
+
144
+ | Model | Scale | Best For | File Size | Speed |
145
+ |-------|-------|----------|-----------|-------|
146
+ | 4x-UltraSharp | 4x | Sharp details, AI-generated images | 64MB | Moderate |
147
+ | RealESRGAN_x2plus | 2x | Moderate upscaling, faster processing | 64MB | Fast |
148
+ | RealESRGAN_x4plus | 4x | General purpose 4x upscaling | 64MB | Moderate |
149
+
150
+ **Model Selection Guide**:
151
+ - **4x-UltraSharp**: Best for AI-generated images needing maximum sharpness
152
+ - **RealESRGAN_x2plus**: Quick 2x upscaling with balanced quality
153
+ - **RealESRGAN_x4plus**: General-purpose 4x upscaling for various image types
154
+
155
+ ## Model Specifications
156
+
157
+ - **Architecture**: RRDB (Residual in Residual Dense Block)
158
+ - **Input Channels**: 3 (RGB)
159
+ - **Output Channels**: 3 (RGB)
160
+ - **Feature Dimensions**: 64
161
+ - **Network Blocks**: 23 (standard configuration)
162
+ - **Growth Channels**: 32
163
+ - **Format**: PyTorch `.pth` files
164
+ - **Precision**: FP32 (supports FP16 inference)
165
+
166
+ ## Performance Tips
167
+
168
+ - **GPU Acceleration**: Use `half=True` for FP16 inference on compatible GPUs (approximately 2x faster)
169
+ - **Tiling for VRAM**: Enable tiling with `tile=512` to reduce VRAM usage for large images
170
+ - **Tile Padding**: Use `tile_pad=10` to minimize visible seams between tiles
171
+ - **Batch Processing**: Process multiple images sequentially to amortize model loading time
172
+ - **CPU Fallback**: Models work on CPU but will be significantly slower (~10-20x)
173
+ - **Optimal Scale**: Use 2x for faster processing, 4x for maximum detail enhancement
174
+ - **Input Quality**: Better input images produce better upscaling results
175
+ - **File Formats**: Use lossless formats (PNG) for best quality preservation
176
+
177
+ ## Use Cases
178
+
179
+ - Post-processing AI-generated images from FLUX.1, Stable Diffusion, etc.
180
+ - Enhancing FLUX.1-dev outputs for high-resolution prints
181
+ - Increasing resolution of generated artwork for commercial use
182
+ - Adding fine details to synthetic images
183
+ - Print preparation for generated images (posters, canvas prints)
184
+ - Upscaling video frames for AI video generation pipelines
185
+ - Restoring and enhancing low-resolution generated content
186
+
187
+ ## Installation
188
+
189
+ ```bash
190
+ pip install realesrgan basicsr
191
+ ```
192
+
193
+ **Dependencies**:
194
+ - Python 3.8+
195
+ - PyTorch 1.7+
196
+ - basicsr
197
+ - realesrgan
198
+ - opencv-python
199
+ - numpy
200
+
201
+ ## License
202
+
203
+ These models are released under the Apache 2.0 license.
204
+
205
+ ## Citation
206
+
207
+ ```bibtex
208
+ @InProceedings{wang2021realesrgan,
209
+ author = {Xintao Wang and Liangbin Xie and Chao Dong and Ying Shan},
210
+ title = {Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data},
211
+ booktitle = {International Conference on Computer Vision Workshops (ICCVW)},
212
+ year = {2021}
213
+ }
214
+ ```
215
+
216
+ ## Links and Resources
217
+
218
+ - **Real-ESRGAN Paper**: [arXiv:2107.10833](https://arxiv.org/abs/2107.10833)
219
+ - **Official Repository**: [xinntao/Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)
220
+ - **BasicSR Library**: [xinntao/BasicSR](https://github.com/xinntao/BasicSR)
221
+ - **Hugging Face**: [Real-ESRGAN Models](https://huggingface.co/models?other=real-esrgan)
222
+ - **Model Downloads**: Available through official Real-ESRGAN releases
223
+
224
+ ## Model Card Contact
225
+
226
+ For questions about Real-ESRGAN models, refer to the official Real-ESRGAN repository and documentation at https://github.com/xinntao/Real-ESRGAN
upscale_models/4x-UltraSharp.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5812231fc936b42af08a5edba784195495d303d5b3248c24489ef0c4021fe01
3
+ size 66961958
upscale_models/RealESRGAN-x2plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49fafd45f8fd7aa8d31ab2a22d14d91b536c34494a5cfe31eb5d89c2fa266abb
3
+ size 67061725
upscale_models/RealESRGAN-x4plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1
3
+ size 67040989
upscale_models/RealESRGAN_x2plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49fafd45f8fd7aa8d31ab2a22d14d91b536c34494a5cfe31eb5d89c2fa266abb
3
+ size 67061725
upscale_models/RealESRGAN_x4plus.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fa0d38905f75ac06eb49a7951b426670021be3018265fd191d2125df9d682f1
3
+ size 67040989