首页>编程相关>Python
  1. 更新在线演示:。这是备份。
  2. 更新在线演示:
  3. GFPGAN的COLAB演示; (原始纸模型的另一个COLAB演示)

感谢您对我们的工作的兴趣。您可能还想检查我们在Real-Esrgan中有关动漫图像和视频小型模型的新更新吗?

GFPGAN旨在开发一种实用算法,用于现实世界的面部修复
它利用封装在经过验证的面孔(例如stylegan2)中的丰富而多样的先验来进行盲人脸部修复。

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

更新


如果GFPGAN在您的照片/项目中有所帮助,请帮助此存储库或向您的朋友推荐。谢谢?其他推荐项目:
▶q Real-esrgan:用于一般图像修复的实用算法
▶q基础知识:开源图像和视频修复工具箱
▶q facexlib:提供有用的面部关系功能的集合
▶q Handyview:基于PYQT5的图像查看器,可用于查看和比较


GFP-GAN:朝着现实世界的盲人面部恢复,具有生成性面部先验

[纸] [项目页] [演示]
Xintao Wang,Yu Li,Honglun Zhang,Ying Shan
应用研究中心(ARC),腾讯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进行安装和推理。

?模型动物园

版本模型名称描述
v1.3 gfpganv1.3.pth基于v1.2;更自然的恢复结果;在非常低质量 /高质量的输入方面更好的结果。
v1.2 gfpgancleanv1-noce-c2.pth没有着色;不需要CUDA扩展。接受了更多数据进行预处理培训。
V1 gfpganv1.pth纸质模型,带有着色。

比较是比较。

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

版本优势弱点
v1.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_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}
}

?接触

如果您有任何疑问,请发送电子邮件[email protected][email protected]

展开
附加信息