21 Commits

Author SHA1 Message Date
Xintao
4f0562df64 fix setup bug 2021-10-22 16:11:17 +08:00
Xintao
eadf03cac8 ReadMe: format discriminator download link 2021-10-06 02:10:27 +08:00
Xintao
a070b88e9e ReadMe: add discriminator download link 2021-10-06 02:08:44 +08:00
Xintao
c2e88f8eb8 add eye_dist_threshold=5 2021-09-27 15:55:20 +08:00
Xintao
69bcfff4ef add codespell 2021-09-27 15:50:44 +08:00
Xintao
e5adc0dd06 add ext option 2021-09-10 18:46:45 +08:00
Xintao
f6d3f70646 update: format and standards 2021-09-08 11:28:21 +08:00
Vincent
ad70ce4653 Reordered requirements (#54)
* Reordered requirements

It had the wrong order, resulting in `basicsr` not wanting to install.

* update order

* add comments

Co-authored-by: Xintao <xintao.alpha@gmail.com>
2021-09-02 00:58:44 +08:00
Xintao
d7cb9f77f1 update readme 2021-08-30 00:09:42 +08:00
Xintao
06ea21690c update open issues 2021-08-29 11:51:56 +08:00
AK391
1d5963b2e6 Add Gradio Web Demo in README.md (#52) 2021-08-29 11:50:17 +08:00
Xintao
7176e63809 update publish-pip 2021-08-28 13:27:10 +08:00
Xintao
3da90f924e add vscode format setting 2021-08-18 10:21:26 +08:00
Xintao
250b75c364 add no-response action workflow 2021-08-18 10:04:42 +08:00
Xintao
1e1c863dae change bg_tile default to 400, update readme 2021-08-18 09:38:35 +08:00
Muhammad Danish
a75e39e323 Update README.md (#43)
upscale_factor is not a recognized argument.
2021-08-18 08:06:36 +08:00
Xintao
11c3957a8f fix save bugs in inference 2021-08-09 20:56:09 +08:00
Xintao
4a7b2cc325 update readme 2021-08-09 02:09:15 +08:00
Xintao
99eda83cce Update README 2021-08-09 02:06:39 +08:00
Xintao
a87388fd2f Update README 2021-08-09 01:59:19 +08:00
Xintao
262ee3399f Update README 2021-08-09 01:57:46 +08:00
14 changed files with 126 additions and 25 deletions

34
.github/workflows/no-response.yml vendored Normal file
View File

@@ -0,0 +1,34 @@
name: No Response
# Modified from: https://raw.githubusercontent.com/github/docs/main/.github/workflows/no-response.yaml
# **What it does**: Closes issues that don't have enough information to be
# actionable.
# **Why we have it**: To remove the need for maintainers to remember to check
# back on issues periodically to see if contributors have
# responded.
# **Who does it impact**: Everyone that works on docs or docs-internal.
on:
issue_comment:
types: [created]
schedule:
# Schedule for five minutes after the hour every hour
- cron: '5 * * * *'
jobs:
noResponse:
runs-on: ubuntu-latest
steps:
- uses: lee-dohm/no-response@v0.5.0
with:
token: ${{ github.token }}
closeComment: >
This issue has been automatically closed because there has been no response
to our request for more information from the original author. With only the
information that is currently in the issue, we don't have enough information
to take action. Please reach out if you have or find the answers we need so
that we can investigate further.
If you still have questions, please improve your description and re-open it.
Thanks :-)

View File

@@ -22,8 +22,7 @@ jobs:
- name: Build and install
run: rm -rf .eggs && pip install -e .
- name: Build for distribution
# remove bdist_wheel for pip installation with compiling cuda extensions
run: python setup.py sdist
run: python setup.py sdist bdist_wheel
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:

View File

@@ -20,10 +20,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 yapf isort
pip install codespell flake8 isort yapf
- name: Lint
run: |
codespell
flake8 .
isort --check-only --diff gfpgan/ scripts/ inference_gfpgan.py setup.py
yapf -r -d gfpgan/ scripts/ inference_gfpgan.py setup.py

1
.gitignore vendored
View File

@@ -7,7 +7,6 @@ wandb/*
tmp/*
version.py
.vscode
# Byte-compiled / optimized / DLL files
__pycache__/

View File

@@ -24,6 +24,12 @@ repos:
hooks:
- id: yapf
# codespell
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
# pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0

19
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"files.trimTrailingWhitespace": true,
"editor.wordWrap": "on",
"editor.rulers": [
80,
120
],
"editor.renderWhitespace": "all",
"editor.renderControlCharacters": true,
"python.formatting.provider": "yapf",
"python.formatting.yapfArgs": [
"--style",
"{BASED_ON_STYLE = pep8, BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF = true, SPLIT_BEFORE_EXPRESSION_AFTER_OPENING_PAREN = true, COLUMN_LIMIT = 120}"
],
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"max-line-length=120"
],
}

View File

@@ -2,7 +2,8 @@
[![download](https://img.shields.io/github/downloads/TencentARC/GFPGAN/total.svg)](https://github.com/TencentARC/GFPGAN/releases)
[![PyPI](https://img.shields.io/pypi/v/gfpgan)](https://pypi.org/project/gfpgan/)
[![Open issue](https://isitmaintained.com/badge/open/TencentARC/GFPGAN.svg)](https://github.com/TencentARC/GFPGAN/issues)
[![Open issue](https://img.shields.io/github/issues/TencentARC/GFPGAN)](https://github.com/TencentARC/GFPGAN/issues)
[![Closed issue](https://img.shields.io/github/issues-closed/TencentARC/GFPGAN)](https://github.com/TencentARC/GFPGAN/issues)
[![LICENSE](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](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)
@@ -14,10 +15,22 @@ GFPGAN aims at developing **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.
:triangular_flag_on_post: **Updates**
- :white_check_mark: 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).
- :white_check_mark: Support enhancing non-face regions (background) with [Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN).
- :white_check_mark: We provide a *clean* version of GFPGAN, which does not require CUDA extensions.
- :white_check_mark: We provide an updated model without colorizing faces.
---
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:<br>
:arrow_forward: [Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN): A practical algorithm for general image restoration<br>
:arrow_forward: [BasicSR](https://github.com/xinntao/BasicSR): An ppen-source image and video restoration toolbox<br>
:arrow_forward: [facexlib](https://github.com/xinntao/facexlib): A collection that provides useful face-relation functions.<br>
:arrow_forward: [HandyView](https://github.com/xinntao/HandyView): A PyQt5-based image viewer that is handy for view and comparison. <br>
---
### :book: GFP-GAN: Towards Real-World Blind Face Restoration with Generative Facial Prior
> [[Paper](https://arxiv.org/abs/2101.04061)] &emsp; [[Project Page](https://xinntao.github.io/projects/gfpgan)] &emsp; [Demo] <br>
@@ -35,7 +48,7 @@ It leverages rich and diverse priors encapsulated in a pretrained face GAN (*e.g
- 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 (We have not tested on Windows)
- Option: Linux
### Installation
@@ -62,6 +75,10 @@ If you want want to use the original model in our paper, please see [PaperModel.
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
@@ -75,14 +92,18 @@ wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1
**Inference!**
```bash
python inference_gfpgan.py --upscale_factor 2 --test_path inputs/whole_imgs --save_root results
python inference_gfpgan.py --upscale 2 --test_path inputs/whole_imgs --save_root results
```
If you want want to use the original model in our paper, please see [PaperModel.md](PaperModel.md) for installation and inference.
## :european_castle: Model Zoo
- [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. It is still in training. Trained with more data with pre-processing.
- [GFPGANv1.pth](https://github.com/TencentARC/GFPGAN/releases/download/v0.1.0/GFPGANv1.pth): The paper model, with colorization.
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)]
## :computer: Training
We provide the training codes for GFPGAN (used in our paper). <br>

View File

@@ -20,7 +20,7 @@ class StyleGAN2GeneratorSFT(StyleGAN2Generator):
StyleGAN2. Default: 2.
resample_kernel (list[int]): A list indicating the 1D resample kernel
magnitude. A cross production will be applied to extent 1D resample
kenrel to 2D resample kernel. Default: [1, 3, 3, 1].
kernel to 2D resample kernel. Default: [1, 3, 3, 1].
lr_mlp (float): Learning rate multiplier for mlp layers. Default: 0.01.
"""

View File

@@ -230,7 +230,7 @@ class GFPGANv1Clean(nn.Module):
self.stylegan_decoder.load_state_dict(
torch.load(decoder_load_path, map_location=lambda storage, loc: storage)['params_ema'])
if fix_decoder:
for name, param in self.stylegan_decoder.named_parameters():
for _, param in self.stylegan_decoder.named_parameters():
param.requires_grad = False
# for SFT

View File

@@ -76,7 +76,8 @@ class GFPGANer():
else:
self.face_helper.read_image(img)
# get face landmarks for each face
self.face_helper.get_face_landmarks_5(only_center_face=only_center_face)
self.face_helper.get_face_landmarks_5(only_center_face=only_center_face, eye_dist_threshold=5)
# eye_dist_threshold=5: skip faces whose eye distance is smaller than 5 pixels
# align and warp each face
self.face_helper.align_warp_face()

View File

@@ -17,13 +17,19 @@ def main():
parser.add_argument('--channel', type=int, default=2)
parser.add_argument('--model_path', type=str, default='experiments/pretrained_models/GFPGANCleanv1-NoCE-C2.pth')
parser.add_argument('--bg_upsampler', type=str, default='realesrgan')
parser.add_argument('--bg_tile', type=int, default=0)
parser.add_argument('--bg_tile', type=int, default=400)
parser.add_argument('--test_path', type=str, default='inputs/whole_imgs')
parser.add_argument('--suffix', type=str, default=None, help='Suffix of the restored faces')
parser.add_argument('--only_center_face', action='store_true')
parser.add_argument('--aligned', action='store_true')
parser.add_argument('--paste_back', action='store_false')
parser.add_argument('--save_root', type=str, default='results')
parser.add_argument(
'--ext',
type=str,
default='auto',
help='Image extension. Options: auto | jpg | png, auto means using the same extension as inputs')
args = parser.parse_args()
args = parser.parse_args()
if args.test_path.endswith('/'):
@@ -71,7 +77,7 @@ def main():
for idx, (cropped_face, restored_face) in enumerate(zip(cropped_faces, restored_faces)):
# save cropped face
save_crop_path = os.path.join(args.save_root, 'cropped_faces', f'{basename}_{idx:02d}.png')
imwrite(restored_face, save_crop_path)
imwrite(cropped_face, save_crop_path)
# save restored face
if args.suffix is not None:
save_face_name = f'{basename}_{idx:02d}_{args.suffix}.png'
@@ -82,12 +88,20 @@ def main():
# save cmp image
cmp_img = np.concatenate((cropped_face, restored_face), axis=1)
imwrite(cmp_img, os.path.join(args.save_root, 'cmp', f'{basename}_{idx:02d}.png'))
# save restored img
if args.suffix is not None:
save_restore_path = os.path.join(args.save_root, 'restored_imgs', f'{basename}_{args.suffix}{ext}')
else:
save_restore_path = os.path.join(args.save_root, 'restored_imgs', img_name)
imwrite(restored_img, save_restore_path)
if restored_img is not None:
if args.ext == 'auto':
extension = ext[1:]
else:
extension = args.ext
if args.suffix is not None:
save_restore_path = os.path.join(args.save_root, 'restored_imgs',
f'{basename}_{args.suffix}.{extension}')
else:
save_restore_path = os.path.join(args.save_root, 'restored_imgs', f'{basename}.{extension}')
imwrite(restored_img, save_restore_path)
print(f'Results are in the [{args.save_root}] folder.')

View File

@@ -1,10 +1,12 @@
facexlib
lmdb
numpy
torch>=1.7
numpy<1.21 # numba requires numpy<1.21,>=1.17
opencv-python
torchvision
scipy
tqdm
basicsr>=1.3.4.0
facexlib>=0.2.0.3
lmdb
pyyaml
tb-nightly
torch>=1.7
torchvision
tqdm
yapf

View File

@@ -20,3 +20,8 @@ known_first_party = gfpgan
known_third_party = basicsr,cv2,facexlib,numpy,torch,torchvision,tqdm
no_lines_before = STDLIB,LOCALFOLDER
default_section = THIRDPARTY
[codespell]
skip = .git,./docs/build
count =
quiet-level = 3

View File

@@ -45,7 +45,7 @@ def get_hash():
sha = get_git_hash()[:7]
elif os.path.exists(version_file):
try:
from facexlib.version import __version__
from gfpgan.version import __version__
sha = __version__.split('+')[-1]
except ImportError:
raise ImportError('Unable to get git version')