Skip to content

Commit 8041b69

Browse files
committed
add paste back and update README
1 parent 4f50996 commit 8041b69

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ GFPGAN is a blind face restoration algorithm towards real-world face images.
88
[Colab Demo](https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo)
99

1010
### :book: GFP-GAN: Towards Real-World Blind Face Restoration with Generative Facial Prior
11-
> [[Paper](https://arxiv.org/abs/2101.04061)] &emsp; [[Project Page](https://xinntao.github.io/projects/gfpgan)] &emsp; [[Demo]()] <br>
11+
> [[Paper](https://arxiv.org/abs/2101.04061)] &emsp; [[Project Page](https://xinntao.github.io/projects/gfpgan)] &emsp; [Demo] <br>
1212
> [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>
1313
> Applied Research Center (ARC), Tencent PCG
1414
1515
#### Abstract
1616

17-
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.
17+
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.
1818

1919
#### BibTeX
2020

@@ -43,18 +43,39 @@ Blind face restoration usually relies on facial priors, such as facial geometry
4343

4444
```bash
4545
git clone https://github.com/xinntao/GFPGAN.git
46+
cd GFPGAN
4647
```
4748

4849
1. Install dependent packages
4950

5051
```bash
51-
cd GFPGAN
52+
# Install basicsr - https://github.com/xinntao/BasicSR
53+
# We use BasicSR for both training and inference
54+
# Set BASICSR_EXT=True to compile the cuda extensions in the BasicSR - It may take several minutes to compile, please be patient
55+
BASICSR_EXT=True pip install basicsr
56+
57+
# Install facexlib - https://github.com/xinntao/facexlib
58+
# We use face detection and face restoration helper in the facexlib package
59+
pip install facexlib
60+
5261
pip install -r requirements.txt
5362
```
5463

5564
## :zap: Quick Inference
5665

57-
> python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs
66+
Download pre-trained models: [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth)
67+
68+
> wget https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth -P experiments/pretrained_models
69+
70+
> python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs
71+
> python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/cropped_faces --aligned
72+
73+
## :computer: Training
74+
75+
We provide a complete training for GFPGAN. <br>
76+
You could improve it according to your own needs.
77+
78+
> python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 train.py -opt train_gfpgan_v1.yml --launcher pytorch
5879

5980
## :scroll: License and Acknowledgement
6081

README_CN.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ GFPGAN is a blind face restoration algorithm towards real-world face images.
88
[Colab Demo](https://colab.research.google.com/drive/1sVsoBd9AjckIXThgtZhGrHRfFI6UUYOo)
99

1010
### :book: GFP-GAN: Towards Real-World Blind Face Restoration with Generative Facial Prior
11-
> [[Paper](https://arxiv.org/abs/2101.04061)] &emsp; [[Project Page](https://xinntao.github.io/projects/gfpgan)] &emsp; [[Demo]()] <br>
11+
> [[Paper](https://arxiv.org/abs/2101.04061)] &emsp; [[Project Page](https://xinntao.github.io/projects/gfpgan)] &emsp; [Demo] <br>
1212
> [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>
1313
> Applied Research Center (ARC), Tencent PCG
1414
1515
#### Abstract
1616

17-
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.
17+
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.
1818

1919
#### BibTeX
2020

@@ -43,18 +43,39 @@ Blind face restoration usually relies on facial priors, such as facial geometry
4343

4444
```bash
4545
git clone https://github.com/xinntao/GFPGAN.git
46+
cd GFPGAN
4647
```
4748

4849
1. Install dependent packages
4950

5051
```bash
51-
cd GFPGAN
52+
# Install basicsr - https://github.com/xinntao/BasicSR
53+
# We use BasicSR for both training and inference
54+
# Set BASICSR_EXT=True to compile the cuda extensions in the BasicSR - It may take several minutes to compile, please be patient
55+
BASICSR_EXT=True pip install basicsr
56+
57+
# Install facexlib - https://github.com/xinntao/facexlib
58+
# We use face detection and face restoration helper in the facexlib package
59+
pip install facexlib
60+
5261
pip install -r requirements.txt
5362
```
5463

5564
## :zap: Quick Inference
5665

57-
> python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs
66+
Download pre-trained models: [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth)
67+
68+
> wget https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth -P experiments/pretrained_models
69+
70+
> python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/whole_imgs
71+
> python inference_gfpgan_full.py --model_path experiments/pretrained_models/GFPGANv1.pth --test_path inputs/cropped_faces --aligned
72+
73+
## :computer: Training
74+
75+
We provide a complete training for GFPGAN. <br>
76+
You could improve it according to your own needs.
77+
78+
> python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 train.py -opt train_gfpgan_v1.yml --launcher pytorch
5879

5980
## :scroll: License and Acknowledgement
6081

inference_gfpgan_full.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
from basicsr.utils import img2tensor, imwrite, tensor2img
1212

1313

14-
def restoration(gfpgan, face_helper, img_path, save_root, has_aligned=False, only_center_face=True, suffix=None):
14+
def restoration(gfpgan,
15+
face_helper,
16+
img_path,
17+
save_root,
18+
has_aligned=False,
19+
only_center_face=True,
20+
suffix=None,
21+
paste_back=False):
1522
# read image
1623
img_name = os.path.basename(img_path)
1724
print(f'Processing {img_name} ...')
@@ -60,6 +67,12 @@ def restoration(gfpgan, face_helper, img_path, save_root, has_aligned=False, onl
6067
cmp_img = np.concatenate((cropped_face, restored_face), axis=1)
6168
imwrite(cmp_img, os.path.join(save_root, 'cmp', f'{basename}_{idx:02d}.png'))
6269

70+
if not has_aligned and paste_back:
71+
face_helper.get_inverse_affine(None)
72+
save_restore_path = os.path.join(save_root, 'restored_imgs', img_name)
73+
# paste each restored face to the input image
74+
face_helper.paste_faces_to_input_image(save_restore_path)
75+
6376

6477
if __name__ == '__main__':
6578
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
@@ -71,6 +84,7 @@ def restoration(gfpgan, face_helper, img_path, save_root, has_aligned=False, onl
7184
parser.add_argument('--suffix', type=str, default=None, help='Suffix of the restored faces')
7285
parser.add_argument('--only_center_face', action='store_true')
7386
parser.add_argument('--aligned', action='store_true')
87+
parser.add_argument('--paste_back', action='store_true')
7488

7589
args = parser.parse_args()
7690
if args.test_path.endswith('/'):
@@ -110,6 +124,7 @@ def restoration(gfpgan, face_helper, img_path, save_root, has_aligned=False, onl
110124
save_root,
111125
has_aligned=args.aligned,
112126
only_center_face=args.only_center_face,
113-
suffix=args.suffix)
127+
suffix=args.suffix,
128+
paste_back=args.paste_back)
114129

115130
print('Results are in the <results> folder.')

0 commit comments

Comments
 (0)