Views
No views yet
4x-UltraSharp.pth - 64MB - 4x upscaling with ultra-sharp detail enhancementRealESRGAN-x2plus.pth - 64MB - 2x upscaling modelRealESRGAN-x4plus.pth - 64MB - 4x upscaling model1from basicsr.archs.rrdbnet_arch import RRDBNet
2from realesrgan import RealESRGANer
3import cv2
4
5# Load the upscaler model
6model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
7
8upsampler = RealESRGANer(
9 scale=4,
10 model_path="E:\\huggingface\\flux-upscale\\upscale_models\\4x-UltraSharp.pth",
11 model=model,
12 tile=0,
13 tile_pad=10,
14 pre_pad=0,
15 half=True # Use FP16 for faster inference on GPU
16)
17
18# Load and upscale an image
19img = cv2.imread("input.png", cv2.IMREAD_COLOR)
20output, _ = upsampler.enhance(img, outscale=4)
21cv2.imwrite("output_upscaled.png", output)1from diffusers import FluxPipeline
2from realesrgan import RealESRGANer
3from basicsr.archs.rrdbnet_arch import RRDBNet
4import torch
5import numpy as np
6
7# Generate image with FLUX
8pipe = FluxPipeline.from_pretrained(
9 "E:\\huggingface\\flux-dev-fp16",
10 torch_dtype=torch.float16
11)
12pipe.to("cuda")
13
14image = pipe(
15 prompt="a beautiful landscape with mountains",
16 num_inference_steps=30
17).images[0]
18
19# Convert PIL to numpy/cv2 format
20img_array = np.array(image)
21
22# Initialize upscaler
23model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
24upsampler = RealESRGANer(
25 scale=4,
26 model_path="E:\\huggingface\\flux-upscale\\upscale_models\\4x-UltraSharp.pth",
27 model=model,
28 half=True
29)
30
31# Upscale the generated image
32upscaled, _ = upsampler.enhance(img_array, outscale=4)
33
34# Save result
35import cv2
36cv2.imwrite("flux_upscaled_4x.png", upscaled)1from basicsr.archs.rrdbnet_arch import RRDBNet
2from realesrgan import RealESRGANer
3import cv2
4
5# Configure for large images with tiling
6model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
7
8upsampler = RealESRGANer(
9 scale=4,
10 model_path="E:\\huggingface\\flux-upscale\\upscale_models\\RealESRGAN_x4plus.pth",
11 model=model,
12 tile=512, # Process in 512x512 tiles
13 tile_pad=10, # Padding to avoid seams
14 pre_pad=0,
15 half=True
16)
17
18# Process large image
19img = cv2.imread("large_image.png", cv2.IMREAD_COLOR)
20output, _ = upsampler.enhance(img, outscale=4)
21cv2.imwrite("large_upscaled.png", output)| Model | Scale | Best For | File Size | Speed |
|---|---|---|---|---|
| 4x-UltraSharp | 4x | Sharp details, AI-generated images | 64MB | Moderate |
| RealESRGAN_x2plus | 2x | Moderate upscaling, faster processing | 64MB | Fast |
| RealESRGAN_x4plus | 4x | General purpose 4x upscaling | 64MB | Moderate |
.pth fileshalf=True for FP16 inference on compatible GPUs (approximately 2x faster)tile=512 to reduce VRAM usage for large imagestile_pad=10 to minimize visible seams between tilespip install realesrgan basicsr1@InProceedings{wang2021realesrgan,
2 author = {Xintao Wang and Liangbin Xie and Chao Dong and Ying Shan},
3 title = {Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data},
4 booktitle = {International Conference on Computer Vision Workshops (ICCVW)},
5 year = {2021}
6}