GFPGAN旨在开发用于现实世界人脸修复的实用算法


GFPGAN 旨在开发一种用于真实世界人脸修复的实用算法

它利用预训练人脸 GAN(例如 StyleGAN2)中封装的丰富多样的先验知识进行盲人脸修复。

其他推荐项目:

▶️ Real-ESRGAN:一种实用的通用图像修复算法
▶️ BasicSR:一个开源的图像和视频修复工具箱
▶️ facexlib:一个提供实用人脸关系函数的库
▶️ HandyView:一个基于 PyQt5 的图像查看器,方便查看和比较

GFP-GAN:基于生成式人脸先验模型的真实世界盲人脸修复

[论文]   [项目页面]   [演示]
王欣涛, 李宇, 张红伦, 单颖
腾讯盈科集团应用研究中心 (ARC)

依赖项和安装

安装

我们现在提供 GFPGAN 的 纯净 版本,它不需要定制的 CUDA 扩展。
如果您想在我们的论文中使用原始模型,请参阅 PaperModel.md 进行安装。

  1. Clone repo

    bash 复制代码
    git clone https://github.com/TencentARC/GFPGAN.git
    cd GFPGAN
  2. Install dependent packages

    bash 复制代码
    # 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

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

推理!

bash 复制代码
python inference_gfpgan.py -i inputs/whole_imgs -o results -v 1.3 -s 2
console 复制代码
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 进行安装和推理。

Model Zoo

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

  1. 更多高质量人脸可以提升修复质量。
  2. 您可能需要进行一些预处理,例如美妆。

程序

您可以尝试不需要面部组件标志的简单版本(options/train_gfpgan_v1_simple.yml)。

  1. 数据集准备: FFHQ

  2. 下载预训练模型和其他数据。将它们放在“experiments/pretrained_models”文件夹中。

    1. 预训练的 StyleGAN2 模型:StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth
    2. FFHQ 的组件位置:FFHQ_eye_mouth_landmarks_512.pth
    3. 一个简单的 ArcFace 模型:arcface_resnet18.pth
  3. 相应地修改配置文件“options/train_gfpgan_v1.yml”。

  4. 训练

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 版下发布。

BibTeX

复制代码
@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}
}

关于项目

GFPGAN 旨在开发一种用于现实世界人脸修复的实用算法。 它利用预训练人脸 GAN(例如 StyleGAN2)中封装的丰富多样的先验知识进行盲人脸修复。
Apache-2.0
Python
37,132
6213
514
2021-03-19
2024-07-27

增长趋势 - stars