Ubuntu+AMD显卡搭建Real-ESRGAN

目前只在Ubuntu20.04+rocm5.2上搭建成功,需要切换到root权限搭建,否则Real-ESRGAN会自动下载nvidia的驱动(可能需要添加到环境变量中),搭建链接:Ubuntu22.04安装AMD显卡驱动和pytorch_V2077的博客-CSDN博客,项目链接:GitHub - xinntao/Real-ESRGAN: Real-ESRGAN aims at developing Practical Algorithms for General Image/Video Restoration.

 安装Real-ESRGAN

$ cd ~
$ git clone https://github.com/xinntao/Real-ESRGAN.git
$ cd Real-ESRGAN

# 安装 basicsr - https://github.com/xinntao/BasicSR
# 我们使用BasicSR来训练以及推断
$ pip install basicsr
# facexlib和gfpgan是用来增强人脸的
$ pip install facexlib
$ pip install gfpgan
$ pip install -r requirements.txt
$ sudo python3 setup.py develop

 图片修复

sudo python3 inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance

视频修复

安装

sudo apt-get -y install ffmpeg && pip3 install ffmpeg

 修复

# rmvb转mp4
$ ffmpeg -i [inputname].rmvb -c:v libx264 -strict -2 [outputname].mp4

$ sudo python3 inference_realesrgan_video.py -n RealESRGAN_x4plus -i inputs.mp4 --face_enhance

或者

$ ffmpeg -i input.mp4 -qscale:v 1 -qmin 1 -qmax 1 -vsync 0 ./inputs/frame%08d.jpg
$ sudo python3 inference_realesrgan.py -n RealESRGAN_x4plus -i inputs --face_enhance
$ ffmpeg -i ./results/frame%08d_out.jpg -i input.mp4 -map 0:v:0 -map 1:a:0 -c:a copy -c:v libx264 -r 23.98 -pix_fmt yuv420p output.mp4

Python 脚本的用法 

Usage: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile -o outfile [options]...

A common command: python inference_realesrgan.py -n RealESRGAN_x4plus -i infile --outscale 3.5 --face_enhance

  -h                   show this help
  -i --input           Input image or folder. Default: inputs
  -o --output          Output folder. Default: results
  -n --model_name      Model name. Default: RealESRGAN_x4plus
  -s, --outscale       The final upsampling scale of the image. Default: 4
  --suffix             Suffix of the restored image. Default: out
  -t, --tile           Tile size, 0 for no tile during testing. Default: 0
  --face_enhance       Whether to use GFPGAN to enhance face. Default: False
  --fp32               Use fp32 precision during inference. Default: fp16 (half precision).
  --ext                Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto

模型下载:

  1. RealESRGAN_x4plus
  2. RealESRNet_x4plus
  3. RealESRGAN_x2plus
  4. realesr-animevideov3
  5. RealESRGAN_x4plus_anime_6B

猜你喜欢

转载自blog.csdn.net/u013636118/article/details/129815508