当前位置:   article > 正文

用代码调用RealESRGAN_x2plus_from basicsr.archs.rrdbnet_arch import rrdbnet

from basicsr.archs.rrdbnet_arch import rrdbnet
  1. import time
  2. import cv2
  3. from basicsr.archs.rrdbnet_arch import RRDBNet
  4. from realesrgan import RealESRGANer
  5. if __name__ == '__main__':
  6. outscale = 1.5
  7. # RealESRGAN_x2plus
  8. model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=2)
  9. netscale = 2
  10. # RealESRNet_x4plus
  11. # model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
  12. # netscale = 4
  13. model_path = 'weights/RealESRGAN_x2plus.pth'
  14. # restorer
  15. upsampler = RealESRGANer(
  16. scale=netscale,
  17. model_path=model_path,
  18. dni_weight=1, # RealESRGAN_x2plus不需要这个参数
  19. model=model,
  20. tile=0,
  21. tile_pad=10,
  22. pre_pad=0,
  23. half=True, # 半精度计算
  24. gpu_id=0)
  25. img = cv2.imread("./demo.jpg", cv2.IMREAD_COLOR)
  26. print(img.shape)
  27. start_time = time.time()
  28. try:
  29. output, _ = upsampler.enhance(img, outscale=outscale)
  30. except RuntimeError as error:
  31. print('Error', error)
  32. print('If you encounter CUDA out of memory, try to set --tile with a smaller number.')
  33. print("time:", time.time() - start_time)
  34. print(output.shape)
  35. cv2.imwrite("./demo2.jpg", output)

经测试RTX3090 512->2048 0.5s

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/442212
推荐阅读
相关标签
  

闽ICP备14008679号