-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsrgan.py
33 lines (28 loc) · 839 Bytes
/
srgan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from realesrgan import RealESRGANer
from basicsr.archs.rrdbnet_arch import RRDBNet
from PIL import Image
import numpy as np
model_path = r'models/RealESRGAN_x2plus.pth'
dni_weight = None
sr_model = RRDBNet(
num_in_ch=3,
num_out_ch=3,
num_feat=64,
num_block=23,
num_grow_ch=32,
scale=2)
device = 'cuda:0'
upsampler = RealESRGANer(
scale=2,
model_path=model_path,
dni_weight=dni_weight,
model=sr_model,
tile=384,
tile_pad=20,
pre_pad=20,
half=False,
device=device,
)
img = np.array(Image.open('test.png').convert('RGB'))
output_img, _ = upsampler.enhance(img, outscale=2)
Image.fromarray(output_img).save('sr.png')