GFPGAN - GFPGAN 旨在开发用于真实世界面部恢复的实用算法。

Created at: 2021-03-19 14:18:20
Language: Python
License: NOASSERTION

下载 PyPI的 未解决的问题 已关闭的问题 许可证  anaconda 绒 发布点数

  1. 💥 更新了在线演示:复制.这是备份
  2. 💥 更新的在线演示:拥抱脸 Gradio
  3. GFPGAN Google Colab 徽标的 Colab 演示 ;(原始纸模型的另一个 Colab 演示

🚀 感谢你对我们工作的关注。你可能还想查看我们关于Real-ESRGAN中动漫图像和视频的微型模型的新更新 😊

GFPGAN旨在开发一种用于真实世界面部修复的实用算法
它利用封装在预训练面部 GAN(例如 StyleGAN2)中的丰富多样的先验进行盲脸恢复。

❓ 常见问题可以在 FAQ.md 中找到。

🚩 更新


如果GFPGAN对你的照片/项目有帮助,请帮助⭐这个回购或推荐给你的朋友。谢谢😊 其他推荐项目: Real-ESRGAN:一种实用的通用图像恢复算法 BasicSR:一个开源的图像和视频恢复
▶️工具箱
▶️ facexlib:提供有用的人脸关系函数
▶️的集合 HandyView
▶️一个基于 PyQt5 的图像查看器,方便查看和比较


📖 GFP-GAN:使用生成式面部先验实现真实世界的盲人面部修复

[论文][项目页面][演示]
王欣涛李宇张红伦, 腾讯PCG盈山
应用技术研究中心


🔧 依赖关系和安装

安装

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

  1. 克隆存储库

    git clone https://github.com/TencentARC/GFPGAN.git
    cd GFPGAN
  2. 安装依赖包

    # 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 进行安装和推理。

🏰 模型动物园

版本 型号名称 描述
1.3版 GFPGANv1.3.pth 基于 V1.2;更自然的恢复效果;在非常低质量/高质量的输入上获得更好的结果。
V1.2版本 GFPGANCleanv1-NoCE-C2.pth 无着色;不需要 CUDA 扩展。通过预处理使用更多数据进行训练。
V1 GFPGANv1.pth 纸张模型,带着色。

比较是 Comparisons.md

请注意,V1.3 并不总是比 V1.2 好。你可能需要根据你的目的和输入选择不同的模型。

版本 优势 弱点
1.3版 ✓ 自然输出 ✓在非常低质量的输入上获得更好的结果 ✓ 在相对高质量的输入上工作


✓ 可以重复(两次)修复
✗ 不是很犀利
✗ 身份略有变化
V1.2版本 ✓ 更清晰的输出
✓ 与美容妆容
✗ 有些输出不自然

你可以在此处找到更多模型(例如鉴别器):[Google Drive]或 [Tencent Cloud 腾讯微云]

💻 训练

我们提供了GFPGAN的训练代码(在我们的论文中使用)。
你可以根据自己的需要对其进行改进。

技巧

  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 options/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}
}

📧 联系

如果你有任何问题,请发送电子邮件或。

xintao.wang@outlook.com
xintaowang@tencent.com