GFPGAN 旨在开发一种用于真实世界人脸修复的实用算法。
它利用预训练人脸 GAN(例如 StyleGAN2)中封装的丰富多样的先验知识进行盲人脸修复。
其他推荐项目:
▶️ Real-ESRGAN:一种实用的通用图像修复算法
▶️ BasicSR:一个开源的图像和视频修复工具箱
▶️ facexlib:一个提供实用人脸关系函数的库
▶️ HandyView:一个基于 PyQt5 的图像查看器,方便查看和比较
我们现在提供 GFPGAN 的 纯净 版本,它不需要定制的 CUDA 扩展。
如果您想在我们的论文中使用原始模型,请参阅 PaperModel.md 进行安装。
Clone repo
git clone https://github.com/TencentARC/GFPGAN.git
cd GFPGAN
Install dependent packages
# Install basicsr - https://github.com/xinntao/BasicSR
# We use BasicSR for both training and inference
pip install basicsr
# Install facexlib - https://github.com/xinntao/facexlib
# We use face detection and face restoration helper in the facexlib package
pip install facexlib
pip install -r requirements.txt
python setup.py develop
# If you want to enhance the background (non-face) regions with Real-ESRGAN,
# you also need to install the realesrgan package
pip install realesrgan
我们以 v1.3 版本为例。更多模型可参见此处。
下载预训练模型: GFPGANv1.3.pth
wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models
推理!
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
如果您想在我们的论文中使用原始模型,请参阅 PaperModel.md 进行安装和推理。
Version | Model Name | Description |
---|---|---|
V1.3 | GFPGANv1.3.pth | 基于 V1.2;更自然的恢复结果;在非常低质量/高质量的输入上获得更好的结果。 |
V1.2 | GFPGANCleanv1-NoCE-C2.pth | 无需着色;无需 CUDA 扩展。使用预处理技术,使用更多数据进行训练。 |
V1 | GFPGANv1.pth | 纸模型,已上色。 |
比较结果位于 Comparisons.md。 请注意,V1.3 并不总是比 V1.2 更好。您可能需要根据您的目的和输入选择不同的模型。
Version | Strengths | Weaknesses |
---|---|---|
V1.3 | ✓ 自然输出 ✓ 在极低质量的输入下也能获得更好的结果 ✓ 能够处理相对高质量的输入 ✓ 可以进行重复(两次)修复 |
✗ not very sharp ✗ 身份略有改变 |
V1.2 | ✓ 输出更清晰 ✓ 具有美妆功能 |
✗ 一些输出是不自然的 |
您可以在这里找到更多模型(例如鉴别器):[Google Drive],或 [Tencent Cloud 腾讯微云]
我们提供了 GFPGAN 的训练代码(用于我们的论文)。
您可以根据自己的需求进行改进。
Tips
程序
您可以尝试不需要面部组件标志的简单版本(options/train_gfpgan_v1_simple.yml
)。
数据集准备: FFHQ
下载预训练模型和其他数据。将它们放在“experiments/pretrained_models”文件夹中。
相应地修改配置文件“options/train_gfpgan_v1.yml”。
训练
python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 gfpgan/train.py -opt 选项/train_gfpgan_v1.yml --launcher pytorch
GFPGAN 在 Apache 许可证 2.0 版下发布。
@InProceedings{wang2021gfpgan,
author = {Xintao Wang and Yu Li and Honglun Zhang and Ying Shan},
title = {Towards Real-World Blind Face Restoration with Generative Facial Prior},
booktitle={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2021}
}