# GFPGAN | Aims At Developing Practical Algorithms For Real World Face Restoration

**URL:** <https://onehack.st/t/gfpgan-aims-at-developing-practical-algorithms-for-real-world-face-restoration/291435>\
**Category:** Tools & Scripts\
**Tags:** tools, programming, business, ai\
**Created:** [September 15, 2024, 7:46pm UTC](https://onehack.st/t/gfpgan-aims-at-developing-practical-algorithms-for-real-world-face-restoration/291435 "2024-09-15T19:46:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheStrength](https://onehack.st/user_avatar/onehack.st/thestrength/32/46753_2.png) [@TheStrength](https://onehack.st/u/TheStrength)\
**Post date:** [September 15, 2024, 7:46pm UTC](https://onehack.st/t/gfpgan-aims-at-developing-practical-algorithms-for-real-world-face-restoration/291435/1 "2024-09-15T19:46:48Z")

</div>

[![](https://github.com/TencentARC/GFPGAN/raw/master/assets/gfpgan_logo.png)](https://github.com/TencentARC/GFPGAN/blob/master/assets/gfpgan_logo.png)

## 

**[English](https://github.com/TencentARC/GFPGAN/blob/master/README.md) | [简体中文](https://github.com/TencentARC/GFPGAN/blob/master/README_CN.md)**

[![download](https://camo.githubusercontent.com/8b288b8eabd770af259a2a3972e8a316e3f0f751eb8f97538b66198979b9ddd3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f646f776e6c6f6164732f54656e63656e744152432f47465047414e2f746f74616c2e737667)](https://github.com/TencentARC/GFPGAN/releases) [![PyPI](https://camo.githubusercontent.com/421fe6fcc9e2e15cdba2c6e21f3ee61b9df67223d1006ed701b748de3d7cf7cf/68747470733a2f2f696d672e736869656c64732e696f2f707970692f762f67667067616e)](https://pypi.org/project/gfpgan/) [![Open issue](https://camo.githubusercontent.com/e157b3761b106f1d3e4eea85c3ac991ca4ac621870f72a3afdf3e54b43086e8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f54656e63656e744152432f47465047414e)](https://github.com/TencentARC/GFPGAN/issues) [![Closed issue](https://camo.githubusercontent.com/4f139ac7859d8c98ec39268f84d31884a3be19b67d19147d7b03b2e3433f59e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d636c6f7365642f54656e63656e744152432f47465047414e)](https://github.com/TencentARC/GFPGAN/issues) [![LICENSE](https://camo.githubusercontent.com/859a1a0bc85ce8bbd7a730a274fec5c9e77c4726ffdf6aa762a78685e26033a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d417061636865253230322e302d626c75652e737667)](https://github.com/TencentARC/GFPGAN/blob/master/LICENSE) [![python lint](https://github.com/TencentARC/GFPGAN/actions/workflows/pylint.yml/badge.svg)](https://github.com/TencentARC/GFPGAN/blob/master/.github/workflows/pylint.yml) [![Publish-pip](https://github.com/TencentARC/GFPGAN/actions/workflows/publish-pip.yml/badge.svg)](https://github.com/TencentARC/GFPGAN/blob/master/.github/workflows/publish-pip.yml)

1. 💥 **Updated** online demo: [![Replicate](https://camo.githubusercontent.com/86328f8c939e36c304e43a7d6937e153927558bcaca87a964f455a3a774f0372/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d44656d6f266d6573736167653d5265706c696361746526636f6c6f723d626c7565)](https://replicate.com/tencentarc/gfpgan). Here is the [backup](https://replicate.com/xinntao/gfpgan).
2. 💥 **Updated** online demo: [![Huggingface Gradio](https://camo.githubusercontent.com/db4090fa0ce3e548764380aea0ee3bce921142566ae76f3bbf343da179670b75/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d44656d6f266d6573736167653d48756767696e676661636525323047726164696f26636f6c6f723d6f72616e6765)](https://huggingface.co/spaces/Xintao/GFPGAN)
3. [Colab Demo](https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo) for GFPGAN [![google colab logo](https://camo.githubusercontent.com/96889048f8a9014fdeba2a891f97150c6aac6e723f5190236b10215a97ed41f3/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667)](https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo); (Another [Colab Demo](https://colab.research.google.com/drive/1Oa1WwKB4M4l1GmR7CtswDVgOCOeSLChA?usp=sharing) for the original paper model)

> 🚀 **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](https://github.com/xinntao/Real-ESRGAN/blob/master/docs/anime_video_model.md)** 😊

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.

❓ Frequently Asked Questions can be found in [FAQ.md](https://github.com/TencentARC/GFPGAN/blob/master/FAQ.md).

🚩 **Updates**

- ✅ Add [RestoreFormer](https://github.com/wzhouxiff/RestoreFormer) inference codes.
- ✅ Add [V1.4 model](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth), which produces slightly more details and better identity than V1.3.
- ✅ Add **[V1.3 model](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth)**, which produces **more natural** restoration results, and better results on _very low-quality_ / _high-quality_ inputs. See more in [Model zoo](https://github.com/TencentARC/GFPGAN#european_castle-model-zoo), [Comparisons.md](https://github.com/TencentARC/GFPGAN/blob/master/Comparisons.md)
- ✅ Integrated to [Huggingface Spaces](https://huggingface.co/spaces) with [Gradio](https://github.com/gradio-app/gradio). See [Gradio Web Demo](https://huggingface.co/spaces/akhaliq/GFPGAN).
- ✅ Support enhancing non-face regions (background) with [Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN).
- ✅ We provide a _clean_ version of GFPGAN, which does not require CUDA extensions.
- ✅ We provide an updated model without colorizing faces.

* * *

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

* * *

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

> [[Paper](https://arxiv.org/abs/2101.04061)] [[Project Page](https://xinntao.github.io/projects/gfpgan)] [Demo]  
> [Xintao Wang](https://xinntao.github.io/), [Yu Li](https://yu-li.github.io/), [Honglun Zhang](https://scholar.google.com/citations?hl=en&user=KjQLROoAAAAJ), [Ying Shan](https://scholar.google.com/citations?user=4oXBp9UAAAAJ&hl=en)  
> Applied Research Center (ARC), Tencent PCG

[![](https://camo.githubusercontent.com/63899e155debe16809806b1bd0263b116304f4949e43d8cdfae1967bdab893a8/68747470733a2f2f78696e6e74616f2e6769746875622e696f2f70726f6a656374732f47465047414e5f7372632f67667067616e5f7465617365722e6a7067)](https://camo.githubusercontent.com/63899e155debe16809806b1bd0263b116304f4949e43d8cdfae1967bdab893a8/68747470733a2f2f78696e6e74616f2e6769746875622e696f2f70726f6a656374732f47465047414e5f7372632f67667067616e5f7465617365722e6a7067)

* * *

## 🔧 Dependencies and Installation

- Python \>= 3.7 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
- [PyTorch \>= 1.7](https://pytorch.org/)
- Option: NVIDIA GPU + [CUDA](https://developer.nvidia.com/cuda-downloads)
- Option: Linux

### 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](https://github.com/TencentARC/GFPGAN/blob/master/PaperModel.md) for installation.

1. Clone repo

git clone [https://github.com/TencentARC/GFPGAN.git](https://github.com/TencentARC/GFPGAN.git) cd GFPGAN

1. Install dependent packages

# Install basicsr - [https://github.com/xinntao/BasicSR](https://github.com/xinntao/BasicSR) # We use BasicSR for both training and inference pip install basicsr # Install facexlib - [https://github.com/xinntao/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

## ⚡ Quick Inference

We take the v1.3 version for an example. More models can be found [here](https://github.com/TencentARC/GFPGAN#european_castle-model-zoo).

Download pre-trained models: [GFPGANv1.3.pth](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth)

wget [https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth](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](https://github.com/TencentARC/GFPGAN/blob/master/PaperModel.md) for installation and inference.

## 🏰 Model Zoo

| Version | Model Name | Description |
| --- | --- | --- |
| V1.3 | [GFPGANv1.3.pth](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/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](https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth) | No colorization; no CUDA extensions are required. Trained with more data with pre-processing. |
| V1 | [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth) | The paper model, with colorization. |

The comparisons are in [Comparisons.md](https://github.com/TencentARC/GFPGAN/blob/master/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](https://drive.google.com/drive/folders/17rLiFzcUMoQuhLnptDsKolegHWwJOnHu?usp=sharing)], OR [[Tencent Cloud 腾讯微云](https://share.weiyun.com/ShYoCCoc)]

## 💻 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](https://github.com/NVlabs/ffhq-dataset)
2. Download pre-trained models and other data. Put them in the `experiments/pretrained_models` folder.
3. [Pre-trained StyleGAN2 model: StyleGAN2\_512\_Cmul1\_FFHQ\_B12G4\_scratch\_800k.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth)
4. [Component locations of FFHQ: FFHQ\_eye\_mouth\_landmarks\_512.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/FFHQ_eye_mouth_landmarks_512.pth)
5. [A simple ArcFace model: arcface\_resnet18.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/arcface_resnet18.pth)
6. Modify the configuration file `options/train_gfpgan_v1.yml` accordingly.
7. Training

> python -m torch.distributed.launch --nproc\_per\_node=4 --master\_port=22021 gfpgan/train.py -opt options/train\_gfpgan\_v1.yml --launcher pytorch

## 📜 License and Acknowledgement

GFPGAN is released under Apache License Version 2.0.

## BibTeX

```auto
@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}
}

```

## 📧 Contact

If you have any question, please email `xintao.wang@outlook.com` or `xintaowang@tencent.com`.

## GitHub:

[https://github.com/TencentARC/GFPGAN](https://github.com/TencentARC/GFPGAN)

---

<div class="post-metadata">

**Author:** ![Darth\_Vader](https://onehack.st/user_avatar/onehack.st/darth_vader/32/97002_2.png) [@Darth\_Vader](https://onehack.st/u/Darth_Vader)\
**Post date:** [September 15, 2024, 7:53pm UTC](https://onehack.st/t/gfpgan-aims-at-developing-practical-algorithms-for-real-world-face-restoration/291435/2 "2024-09-15T19:53:57Z")

</div>

Have a high end system ready OR run it in Cloud GPUs
