GFP-GAN由腾讯ARC实验室出品,测试下来效果很不错。
模型用于从低质量的人脸中恢复出高质量人脸。这些质量较低的肖像图可能由各种原因导致退化,如低分辨率,噪音,模糊或是被压缩。
主流的图像修复技术还是对抗生成网络GAN,但如何用好GAN是个学问。本模型使用了生成性面部先验模型(Generative Facial Prior, GFP),通过空间特征变换层被纳入到面部恢复过程中,这使得该方法能够实现真实性和保真度的良好平衡。
目前有3个pretrain模型,默认使用v1.3:
模型总图如下:
去退化模块为一个UNet,在UNet解码器的每个分辨率尺度输出图像,使用L1损失函数监督去退化模块。
将styleGAN的生成器拿过来直接用~
用经过了重建损失函数的
F
s
p
a
t
i
a
l
F_{spatial}
Fspatial可以更好的提高保真性,与前面的
F
G
A
N
F_{GAN}
FGAN进行连接,连接方法为SFT。
保真性损失使用ArcFace人脸识别模型。
- https://huggingface.co/spaces/akhaliq/GFPGAN,仅返回人脸
- https://app.baseten.co/applications/Q04Lz0d/operator_views/8qZG6Bg,GPU backened,速度很快,而且可以返回全图
- https://replicate.com/xinntao/gfpgan,需要注册,返回全图
- colab demo地址:https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo
https://github.com/TencentARC/GFPGAN
git clone https://github.com/TencentARC/GFPGAN.git cd GFPGAN pip install basicsr # 用于推理和训练,https://github.com/xinntao/BasicSR pip install facexlib # 用于人脸检测,https://github.com/xinntao/facexlib pip install -r requirements.txt python setup.py develop pip install realesrgan # 非人脸区域超分,使用Real-ESRGAN
然后下载模型,这里可以离线下载:
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models no-check-certificate
执行推理:
python inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.3 -s 2
参数说明如下:
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
如果用cpu的话,有几个地方需要修改:
- inference_gfpgan.py中,允许cpu,并将half改为False:
此外,python3.7/site-packages/facexlib/utils中加上兼容cpu的代码:



