import time
import cv2
from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer
if __name__ == '__main__':
outscale = 1.5
# RealESRGAN_x2plus
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
netscale = 2
# RealESRNet_x4plus
# model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
# netscale = 4
model_path = 'weights/RealESRGAN_x2plus.pth'
# restorer
upsampler = RealESRGANer(
scale=netscale,
model_path=model_path,
dni_weight=1, # RealESRGAN_x2plus不需要这个参数
model=model,
tile=0,
tile_pad=10,
pre_pad=0,
half=True, # 半精度计算
gpu_id=0)
img = cv2.imread("./demo.jpg", cv2.IMREAD_COLOR)
print(img.shape)
start_time = time.time()
try:
output, _ = upsampler.enhance(img, outscale=outscale)
except RuntimeError as error:
print('Error', error)
print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
print("time:", time.time() - start_time)
print(output.shape)
cv2.imwrite("./demo2.jpg", output)
经测试RTX3090 512->2048 0.5s