原文链接:http://www.juzicode.com/image-photo-editor-gfpgan
今天桔子菌给大家介绍一款模糊老照片的修复神器~GFPGAN。
首先看下网页版,进入到GFPGAN - a Hugging Face Space by akhaliq,界面非常简单易用,
点击左侧的click to upload添加进要修复的图片,再点击submit按钮,在右侧就可以看到修复后的图片了,生成的图片还可以下载到本地保存。
从下面这个例子中可以看到图像清晰了不少,牙缝清晰可见、眼神更有光亮、发尖细丝可数。
再放一张薛大神的照片,他养了一条闻名世界的猫:
如果你想体验DIY的乐趣,也可以进入https://github.com/TencentARC/GFPGAN 将整个工程下载到本地执行。
网页方式下载zip格式,解压后整个目录结构是这样的:
因为模型文件比较大,并行处理可节约时间,先到https://github.com/TencentARC/GFPGAN/releases/tag/v0.2.0 找到GFPGANCleanv1-NoCE-C2.pth模型文件,下载完成后拷贝到experiments\pretrained_models目录下:
下载模型文件的同时安装依赖包,打开requirements.txt,可以看到依赖包的种类:
- torch>=1.7
- numpy<1.21 # numba requires numpy<1.21,>=1.17
- opencv-python
- torchvision
- scipy
- tqdm
- basicsr>=1.3.4.0
- facexlib>=0.2.0.3
- lmdb
- pyyaml
- tb-nightly
- yapf
安装requirements.txt包含的依赖包:
pip install -r requirements.txt
安装完这些依赖包,接着安装gfpgan本身:
python setup.py develop
如果要使用到背景增强功能,还需要安装realesrgan模块:
pip install realesrgan
接下来运行py文件:
python inference_gfpgan.py --upscale 2 --test_path inputs/whole_imgs --save_root results
其中–test_path参数inputs/whole_imgs是待处理图片所在的文件夹, –save_root参数results是处理后图片所在的文件夹。
第一次运行时会比较慢,还会额外自动下载facexlib的模型文件:
- E:\juzicode\image\GFPGAN-master>python inference_gfpgan.py --upscale 2 --test_path inputs/whole_imgs --save_root results
- inference_gfpgan.py:45: UserWarning: The unoptimized RealESRGAN is very slow on CPU. We do not use it. If you really want to use it, please modify the corresponding codes.
- warnings.warn('The unoptimized RealESRGAN is very slow on CPU. We do not use it. '
- Downloading: "https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth" to D:\Python\vPy38Gfpgan\lib\site-packages\facexlib\weights\detection_Resnet50_Final.pth
- 100%|████████████████████████████████████████████████████████████████████████████████| 104M/104M [12:25<00:00, 147kB/s]
稍后片刻就能在results\cmp目录下看到修复前后的对比图片了:
联系客服