利用腾讯云GPU云服务器搭建GFPGAN模型实现老照片修复

随着人工智能的发展,AI技术已经被应用到各行各业,为人们的工作生活提供诸多便利。有了现在的技术,人们可以修复那些充满了珍贵会议的老照片,本文就以国内云服务器商腾讯云提供的云服务为例,为大家介绍利用腾讯云GPU云服务器+GFPGAN实现实现老照片修复,教程仅供参考。

本文涉及到的腾讯云服务:腾讯云GPU云服务器

腾讯云GPU云服务器提供GPU算力,主要应用于深度学习训练/推理、图形图像处理以及科学计算等场景。提供包年包月和按量计费两种计费模式,提供丰富的配置方案可选,用户可以按需选择合适的方案。

腾讯云GPU云服务器

点击进入官网选购

一、购买腾讯云GPU云服务器

1、进入腾讯云官网,注册后登录。

2、点击“服务”>“计算”>“GPU云服务器”。

腾讯云GPU云服务器

3、在以下页面点击“立即选购”。

腾讯云GPU云服务器

4、进入GPU云服务器购买页面,按照需求选择合适的配置。

  • 操作系统:CentOS 7.6 64位
  • NVIDIA显卡:至少4GB显存
  • 镜像:Tesla Driver+CUDA

5、完成所需配置,确认无误后,付款即可。

6、付款完成后,进入控制台,待实例创建启动完毕,即可进行登录操作。

7、登录GPU云服务器实例。

二、搭建GFPGAN模型

1、安装GFPGAN的运行环境

Python >= 3.7 (Recommend to use Anaconda or Miniconda) PyTorch >= 1.7 Option: NVIDIA GPU + CUDA Option: Linux

2、安装GFPGAN

Clone repo

git clone https://github.com/TencentARC/GFPGAN.git cd GFPGAN

Install dependent packages

pip3 install basicsr pip3 install facexlib pip3 install -r requirements.txt python3 setup.py develop pip3 install realesrgan

3、下载训练模型

v1.3

wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models

v1.2

wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P experiments/pretrained_models

Usage: python inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.3 -s 2 [options]... -h show this help -i input Input image or folder. Default: inputs/whole_imgs -o output Output folder. Default: results -v version GFPGAN model version. Option: 1 | 1.2 | 1.3. Default: 1.3 -s upscale The final upsampling scale of the image. Default: 2 -bg_upsampler background upsampler. Default: realesrgan -bg_tile Tile size for background sampler, 0 for no tile during testing. Default: 400 -suffix Suffix of the restored faces -only_center_face Only restore the center face -aligned Input are aligned faces -ext Image extension. Options: auto | jpg | png, auto means using the same extension as inputs. Default: auto

实测

python3 inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.3 -s 2

通过rz命令上传了一张测试图片到inputs/test_imgs,分别用v1.2和v1.3的模型对照片进行修复。

腾讯云老照片修复

python3 inference_gfpgan.py -i inputs/whole_imgs -o results/test/1.2 -v 1.2 -s 2 python3 inference_gfpgan.py -i inputs/whole_imgs -o results/test/1.3 -v 1.3 -s 2 执行命令的提示: Processing test.png ... Results are in the [results/test/1.2] folder.

tree results查看results的目录结构

results

-- test |-- 1.2 |-- cmp | -- test_00.png |-- cropped_faces | -- test_00.png |-- restored_faces | -- test_00.png |-- restored_imgs -- test.png |-- 1.3 |-- cmp | -- test_00.png |-- cropped_faces | -- test_00.png |-- restored_faces | -- test_00.png |-- restored_imgs -- test.png

其中restored_imgs下的图片就是最后的结果。

腾讯云老照片修复

使用教程

亚马逊云科技教程:Inferentia2+EC2部署DeepSeek-R1模型

2025-6-18 16:08:00

其他

什么是华为云服务器?华为云服务器的优势介绍

2023-2-24 16:47:22

相关推荐