GFPGAN README

The project's README from github.com/TencentARC/GFPGAN. As one markdown file: README.md.

English | 简体中文

download PyPI Open issue Closed issue LICENSE python lint Publish-pip

  1. :boom: Updated online demo: Replicate. Here is the backup.
  2. :boom: Updated online demo: Huggingface Gradio
  3. Colab Demo for GFPGAN google colab logo; (Another Colab Demo for the original paper model)

:rocket: Thanks for your interest in our work. You may also want to check our new updates on the tiny models for anime images and videos in Real-ESRGAN :blush:

GFPGAN aims at developing a Practical Algorithm for Real-world Face Restoration.
It leverages rich and diverse priors encapsulated in a pretrained face GAN (e.g., StyleGAN2) for blind face restoration.

:question: Frequently Asked Questions can be found in FAQ.md.

:triangular_flag_on_post: Updates


If GFPGAN is helpful in your photos/projects, please help to :star: this repo or recommend it to your friends. Thanks:blush: Other recommended projects:
:arrow_forward: Real-ESRGAN: A practical algorithm for general image restoration
:arrow_forward: BasicSR: An open-source image and video restoration toolbox
:arrow_forward: facexlib: A collection that provides useful face-relation functions
:arrow_forward: HandyView: A PyQt5-based image viewer that is handy for view and comparison


:book: GFP-GAN: Towards Real-World Blind Face Restoration with Generative Facial Prior

[Paper]   [Project Page]   [Demo]
Xintao Wang, Yu Li, Honglun Zhang, Ying Shan
Applied Research Center (ARC), Tencent PCG


:wrench: Dependencies and Installation

Installation

We now provide a clean version of GFPGAN, which does not require customized CUDA extensions.
If you want to use the original model in our paper, please see PaperModel.md for installation.

  1. Clone repo

    git clone https://github.com/TencentARC/GFPGAN.git
    cd GFPGAN
    
  2. 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
    

:zap: Quick Inference

We take the v1.3 version for an example. More models can be found here.

Download pre-trained models: GFPGANv1.3.pth

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

Inference!

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

If you want to use the original model in our paper, please see PaperModel.md for installation and inference.

:european_castle: Model Zoo

Version Model Name Description
V1.3 GFPGANv1.3.pth Based on V1.2; more natural restoration results; better results on very low-quality / high-quality inputs.
V1.2 GFPGANCleanv1-NoCE-C2.pth No colorization; no CUDA extensions are required. Trained with more data with pre-processing.
V1 GFPGANv1.pth The paper model, with colorization.

The comparisons are in Comparisons.md.

Note that V1.3 is not always better than V1.2. You may need to select different models based on your purpose and inputs.

Version Strengths Weaknesses
V1.3 ✓ natural outputs
✓better results on very low-quality inputs
✓ work on relatively high-quality inputs
✓ can have repeated (twice) restorations
✗ not very sharp
✗ have a slight change on identity
V1.2 ✓ sharper output
✓ with beauty makeup
✗ some outputs are unnatural

You can find more models (such as the discriminators) here: [Google Drive], OR [Tencent Cloud 腾讯微云]

:computer: Training

We provide the training codes for GFPGAN (used in our paper).
You could improve it according to your own needs.

Tips

  1. More high quality faces can improve the restoration quality.
  2. You may need to perform some pre-processing, such as beauty makeup.

Procedures

(You can try a simple version ( options/train_gfpgan_v1_simple.yml) that does not require face component landmarks.)

  1. Dataset preparation: FFHQ

  2. Download pre-trained models and other data. Put them in the experiments/pretrained_models folder.

    1. Pre-trained StyleGAN2 model: StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth
    2. Component locations of FFHQ: FFHQ_eye_mouth_landmarks_512.pth
    3. A simple ArcFace model: arcface_resnet18.pth
  3. Modify the configuration file options/train_gfpgan_v1.yml accordingly.

  4. Training

python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 gfpgan/train.py -opt options/train_gfpgan_v1.yml --launcher pytorch

:scroll: License and Acknowledgement

GFPGAN is released under Apache License Version 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}
}

:e-mail: Contact

If you have any question, please email [email protected] or [email protected].

GFPGAN (TencentARC/GFPGAN)

Searching Database…

37.7K ·GitHub
这是干什么的?GFPGAN 是一个实用的真实场景盲人脸修复算法:它借助 StyleGAN2 这类预训练人脸 GAN 中丰富的先验知识,来重建照片中退化或低质量的人脸。
GFPGAN 是一个打开就能用的应用,还是我自己运行的 Python 工具?它是一个需要你自己运行的 Python 包——用 pip 安装后,在脚本或命令行里调用。如果你只是想试试,也有在线的 Colab 和 Gradio 网页演示。
我怎么用它修复第一张照片?安装 Python >= 3.7 和 PyTorch >= 1.7,克隆仓库并安装依赖包,然后下载一个预训练模型(比如 GFPGANv1.3.pth),再运行推理脚本。
我该选哪个模型版本?先用最新的 V1.4 或热门的 V1.3:效果自然,也能处理质量很差的输入,但不够锐利,而且会轻微改变人脸 identity。V1.2 更锐利,但有些输出看起来不自然。
这是给开发者用的,还是任何人都能修复老照片?主要面向熟悉 Python 和 PyTorch 的开发者和研究人员,但不会编程的人也能用——直接在浏览器里通过 Colab 和 Hugging Face 的 Gradio 演示修复照片。
运行它需要 NVIDIA 显卡吗?带 CUDA 的 NVIDIA 显卡不是必需的。GFPGAN 的干净版本不需要自定义 CUDA 扩展,所以没有 GPU 也能运行;只有论文里的原始模型(V1)需要它们——详见 PaperModel.md。
GFPGAN 只修复人脸,还是整张照片都能修?人脸是它的核心强项;背景和其他非人脸区域也可以增强,用的是同一作者推出的通用图像修复模型 Real-ESRGAN。
我能用自己的数据训练 GFPGAN 吗?可以,论文使用的训练代码都包含在内。README 建议更多高质量人脸数据能提升效果,并提供了一个无需人脸关键点组件的简单配置。
它能处理动漫图片或视频吗?不能直接处理——GFPGAN 面向真实场景照片。对于动漫图片和视频,作者建议使用他们加到 Real-ESRGAN 项目里的小型模型。
Creator
TencentARC
Size
5.3 MB
Stars
37.7K
Age
5y
Commits · 90 Days