8000 Merge pull request #33 from TencentARC/readme · coder-wuyan/GFPGAN@401cf51 · GitHub
[go: up one dir, main page]

Skip to content

Commit 401cf51

Browse files
authored
Merge pull request TencentARC#33 from TencentARC/readme
Update ReadMe
2 parents 7f67e12 + d507feb commit 401cf51

File tree

5 files changed

+340
-167
lines changed

5 files changed

+340
-167
lines changed

PaperModel.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Installation
2+
3+
We now provide a *clean* version of GFPGAN, which does not require customized CUDA extensions. See [here](README.md#installation) for this easier installation.<br>
4+
If you want want to use the original model in our paper, please follow the instructions below.
5+
6+
1. Clone repo
7+
8+
```bash
9+
git clone https://github.com/xinntao/GFPGAN.git
10+
cd GFPGAN
11+
```
12+
13+
1. Install dependent packages
14+
15+
As StyleGAN2 uses customized PyTorch C++ extensions, you need to **compile them during installation** or **load them just-in-time(JIT)**.
16+
You can refer to [BasicSR-INSTALL.md](https://github.com/xinntao/BasicSR/blob/master/INSTALL.md) for more details.
17+
18+
**Option 1: Load extensions just-in-time(JIT)** (For those just want to do simple inferences, may have less issues)
19+
20+
```bash
21+
# Install basicsr - https://github.com/xinntao/BasicSR
22+
# We use BasicSR for both training and inference
23+
pip install basicsr
24+
25+
# Install facexlib - https://github.com/xinntao/facexlib
26+
# We use face detection and face restoration helper in the facexlib package
27+
pip install facexlib
28+
29+
pip install -r requirements.txt
30+
31+
# remember to set BASICSR_JIT=True before your running commands
32+
```
33+
34+
**Option 2: Compile extensions during installation** (For those need to train/inference for many times)
35+
36+
```bash
37+
# Install basicsr - https://github.com/xinntao/BasicSR
38+
# We use BasicSR for both training and inference
39+
# Set BASICSR_EXT=True to compile the cuda extensions in the BasicSR - It may take several minutes to compile, please be patient
40+
# Add -vvv for detailed log prints
41+
BASICSR_EXT=True pip install basicsr -vvv
42+
43+
# Install facexlib - https://github.com/xinntao/facexlib
44+
# We use face detection and face restoration helper in the facexlib package
45+
pip install facexlib
46+
47+
pip install -r requirements.txt
48+
```
49+
50+
## :zap: Quick Inference
51+
52+
Download pre-trained models: [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth)
53+
54+
```bash
55+
wget https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth -P experiments/pretrained_models
56+
```
57+
58+
- Option 1: Load extensions just-in-time(JIT)
59+
60+
```bash
61+
BASICSR_JIT=True python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs --save_root results --arch original --channel 1
62+
63+
# for aligned images
64+
BASICSR_JIT=True python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs --save_root results --arch original --channel 1 --aligned
65+
```
66+
67+
- Option 2: Have successfully compiled extensions during installation
68+
69+
```bash
70+
python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs --save_root results --arch original --channel 1
71+
72+
# for aligned images
73+
python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs --save_root results --arch original --channel 1 --aligned
74+
```

README.md

Lines changed: 43 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,23 @@
55
[![LICENSE](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/TencentARC/GFPGAN/blob/master/LICENSE)
66
[![python lint](https://github.com/TencentARC/GFPGAN/actions/workflows/pylint.yml/badge.svg)](https://github.com/TencentARC/GFPGAN/blob/master/.github/workflows/pylint.yml)
77

8-
[**Paper**](https://arxiv.org/abs/2101.04061) **|** [**Project Page**](https://xinntao.github.io/projects/gfpgan) &emsp;&emsp; [English](README.md) **|** [简体中文](README_CN.md)
8+
1. [Colab Demo](https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo) for GFPGAN <a href="https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>
9+
1. We provide a *clean* version of GFPGAN, which can run without CUDA extensions. So that it can run in **Windows** or on **CPU mode**.
910

10-
GFPGAN is a blind face restoration algorithm towards real-world face images.
11+
GFPGAN aims at developing **Practical Algorithm for Real-world Face Restoration**.<br>
12+
It leverages rich and diverse priors encapsulated in a pretrained face GAN (*e.g.*, StyleGAN2) for blind face restoration.
1113

12-
<a href="https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="google colab logo"></a>
13-
[Colab Demo](https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo)
14+
:triangular_flag_on_post: **Updates**
15+
16+
- :white_check_mark: We provide a *clean* version of GFPGAN, which does not require CUDA extensionts.
17+
- :white_check_mark: We provide an updated model without colorizing faces.
1418

1519
### :book: GFP-GAN: Towards Real-World Blind Face Restoration with Generative Facial Prior
20+
1621
> [[Paper](https://arxiv.org/abs/2101.04061)] &emsp; [[Project Page](https://xinntao.github.io/projects/gfpgan)] &emsp; [Demo] <br>
1722
> [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) <br>
1823
> Applied Research Center (ARC), Tencent PCG
1924
20-
#### Abstract
21-
22-
Blind face restoration usually relies on facial priors, such as facial geometry prior or reference prior, to restore realistic and faithful details. However, very low-quality inputs cannot offer accurate geometric prior while high-quality references are inaccessible, limiting the applicability in real-world scenarios. In this work, we propose GFP-GAN that leverages **rich and diverse priors encapsulated in a pretrained face GAN** for blind face restoration. This Generative Facial Prior (GFP) is incorporated into the face restoration process via novel channel-split spatial feature transform layers, which allow our method to achieve a good balance of realness and fidelity. Thanks to the powerful generative facial prior and delicate designs, our GFP-GAN could jointly restore facial details and enhance colors with just a single forward pass, while GAN inversion methods require expensive image-specific optimization at inference. Extensive experiments show that our method achieves superior performance to prior art on both synthetic and real-world datasets.
23-
24-
#### BibTeX
25-
26-
@InProceedings{wang2021gfpgan,
27-
author = {Xintao Wang and Yu Li and Honglun Zhang and Ying Shan},
28-
title = {Towards Real-World Blind Face Restoration with Generative Facial Prior},
29-
booktitle={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
30-
year = {2021}
31-
}
32-
3325
<p align="center">
3426
<img src="https://xinntao.github.io/projects/GFPGAN_src/gfpgan_teaser.jpg">
3527
</p>
@@ -40,25 +32,23 @@ Blind face restoration usually relies on facial priors, such as facial geometry
4032

4133
- Python >= 3.7 (Recommend to use [Anaconda](https://www.anaconda.com/download/#linux) or [Miniconda](https://docs.conda.io/en/latest/miniconda.html))
4234
- [PyTorch >= 1.7](https://pytorch.org/)
43-
- NVIDIA GPU + [CUDA](https://developer.nvidia.com/cuda-downloads)
44-
- Linux (We have not tested on Windows)
35+
- Option: NVIDIA GPU + [CUDA](https://developer.nvidia.com/cuda-downloads)
36+
- Option: Linux (We have not tested on Windows)
4537

4638
### Installation
4739

40+
We now provide a *clean* version of GFPGAN, which does not require customized CUDA extensions. <br>
41+
If you want want to use the original model in our paper, please see [PaperModel.md](PaperModel.md) for installation.
42+
4843
1. Clone repo
4944

5045
```bash
51-
git clone https://github.com/xinntao/GFPGAN.git
46+
git clone https://github.com/TencentARC/GFPGAN.git
5247
cd GFPGAN
5348
```
5449

5550
1. Install dependent packages
5651

57-
As StyleGAN2 uses customized PyTorch C++ extensions, you need to **compile them during installation** or **load then just-in-time(JIT)**.
58-
You can refer to [BasicSR-INSTALL.md](https://github.com/xinntao/BasicSR/blob/master/INSTALL.md) for more details.
59-
60-
**Option 1: Load extensions just-in-time(JIT)** (For those just want to do simple inferences, may have less issues)
61-
6252
```bash
6353
# Install basicsr - https://github.com/xinntao/BasicSR
6454
# We use BasicSR for both training and inference
@@ -69,56 +59,41 @@ Blind face restoration usually relies on facial priors, such as facial geometry
6959
pip install facexlib
7060
7161
pip install -r requirements.txt
72-
73-
# remember to set BASICSR_JIT=True before your running commands
7462
```
7563

76-
**Option 2: Compile extensions during installation** (For those need to train/inference for many times)
77-
78-
```bash
79-
# Install basicsr - https://github.com/xinntao/BasicSR
80-
# We use BasicSR for both training and inference
81-
# Set BASICSR_EXT=True to compile the cuda extensions in the BasicSR - It may take several minutes to compile, please be patient
82-
# Add -vvv for detailed log prints
83-
BASICSR_EXT=True pip install basicsr -vvv
84-
85-
# Install facexlib - https://github.com/xinntao/facexlib
86-
# We use face detection and face restoration helper in the facexlib package
87-
pip install facexlib
64+
## :zap: Quick Inference
8865

89-
pip install -r requirements.txt
90-
```
66+
Download pre-trained models: [GFPGANCleanv1-NoCE-C2.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth)
9167

92-
## :zap: Quick Inference
68+
```bash
69+
wget https://github.com/Ten 6377 centARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P experiments/pretrained_models
70+
```
9371

94-
Download pre-trained models: [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth)
72+
**Inference!**
9573

9674
```bash
97-
wget https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth -P experiments/pretrained_models
75+
python inference_gfpgan_full.py --upscale_factor 2 --test_path inputs/whole_imgs --save_root results
9876
```
9977

100-
- Option 1: Load extensions just-in-time(JIT)
78+
## :european_castle: Model Zoo
10179

102-
```bash
103-
BASICSR_JIT=True python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs
80+
- [GFPGANCleanv1-NoCE-C2.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth)
81+
- [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth)
10482

105-
# for aligned images
106-
BASICSR_JIT=True python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/cropped_faces --aligned
107-
```
83+
## :computer: Training
10884

109-
- Option 2: Have successfully compiled extensions during installation
85+
We provide the training codes for GFPGAN (used in our paper). <br>
86+
You could improve it according to your own needs.
11087

111-
```bash
112-
python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs
88+
**Tips**
11389

114-
# for aligned images
115-
python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/cropped_faces --aligned
116-
```
90+
1. More high quality faces can improve the restoration quality.
91+
2. You may need to perform some pre-processing, such as beauty makeup.
11792

118-
## :computer: Training
11993

120-
We provide complete training codes for GFPGAN. <br>
121-
You could improve it according to your own needs.
94+
**Procedures**
95+
96+
(You can try a simple version ( `train_gfpgan_v1_simple.yml`) that does not require face component landmarks.)
12297

12398
1. Dataset preparation: [FFHQ](https://github.com/NVlabs/ffhq-dataset)
12499

@@ -133,13 +108,18 @@ You could improve it according to your own needs.
133108

134109
> python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 train.py -opt train_gfpgan_v1.yml --launcher pytorch
135110

136-
or load extensions just-in-time(JIT)
111+
## :scroll: License and Acknowledgement
137112

138-
> BASICSR_JIT=True python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 train.py -opt train_gfpgan_v1.yml --launcher pytorch
113+
GFPGAN is released under Apache License Version 2.0.
139114

140-
## :scroll: License and Acknowledgement
115+
## BibTeX
141116

142-
GFPGAN is realeased under Apache License Version 2.0.
117+
@InProceedings{wang2021gfpgan,
118+
author = {Xintao Wang and Yu Li and Honglun Zhang and Ying Shan},
119+
title = {Towards Real-World Blind Face Restoration with Generative Facial Prior},
120+
booktitle={The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
121+
year = {2021}
122+
}
143123

144124
## :e-mail: Contact
145125

README_CN.md

Lines changed: 0 additions & 103 deletions
This file was deleted.

train_gfpgan_v1.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ datasets:
3434
color_jitter_pt_prob: 0.3
3535
gray_prob: 0.01
3636

37+
# If you do not want colorization, please set
38+
# color_jitter_prob: ~
39+
# color_jitter_pt_prob: ~
40+
# gray_prob: 0.01
41+
# gt_gray: True
42+
3743
crop_components: true
3844
component_path: experiments/pretrained_models/FFHQ_eye_mouth_landmarks_512.pth
3945
eye_enlarge_ratio: 1.4
@@ -42,7 +48,7 @@ datasets:
4248
use_shuffle: true
4349
num_worker_per_gpu: 6
4450
batch_size_per_gpu: 3
45-
dataset_enlarge_ratio: 100
51+
dataset_enlarge_ratio: 1
4652
prefetch_mode: ~
4753

4854
val:

0 commit comments

Comments
 (0)
0