Package: gfpgan
English|简体中文:boom:Updatedonline demo:. Here is thebackup.:boom:Updatedonline demo:Colab Demofor GFPGAN; (AnotherColab Demofor the original paper model):rocket:Thanks for your interest in our work. You may also want to check our new updates on thetiny modelsforanime images and videosinReal-ESRGAN:blush:GFPGAN aims at developing aPractical 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 inFAQ.md.:triangular_flag_on_post:Updates:white_check_mark: AddRestoreFormerinference codes.:white_check_mark: AddV1.4 model, which produces slightly more details and better identity than V1.3.:white_check_mark: AddV1.3 model, which producesmore naturalrestoration results, and better results onvery low-quality/high-qualityinputs. See more inModel zoo,Comparisons.md:white_check_mark: Integrated toHuggingface SpaceswithGradio. SeeGradio Web Demo.:white_check_mark: Support enhancing non-face regions (background) withReal-ESRGAN.:white_check_mark: We provide acleanversion 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::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 ShanApplied Research Center (ARC), Tencent PCG:wrench: Dependencies and InstallationPython >= 3.7 (Recommend to useAnacondaorMiniconda)PyTorch >= 1.7Option: NVIDIA GPU +CUDAOption: LinuxInstallationWe now provide acleanversion of GFPGAN, which does not require customized CUDA extensions.If you want to use the original model in our paper, please seePaperModel.mdfor installation.Clone repogitclonehttps://github.com/TencentARC/GFPGAN.gitcdGFPGANInstall dependent packages# Install basicsr - https://github.com/xinntao/BasicSR# We use BasicSR for both training and inferencepipinstallbasicsr# Install facexlib - https://github.com/xinntao/facexlib# We use face detection and face restoration helper in the facexlib packagepipinstallfacexlib

pipinstall-rrequirements.txt
pythonsetup.pydevelop# If you want to enhance the background (non-face) regions with Real-ESRGAN,# you also need to install the realesrgan packagepipinstallrealesrgan:zap: Quick InferenceWe take the v1.3 version for an example. More models can be foundhere.Download pre-trained models:GFPGANv1.3.pthwgethttps://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth-Pexperiments/pretrained_modelsInference!pythoninference_gfpgan.py-iinputs/whole_imgs-oresults-v1.3-s2Usage: 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: autoIf you want to use the original model in our paper, please seePaperModel.mdfor installation and inference.:european_castle: Model ZooVersionModel NameDescriptionV1.3GFPGANv1.3.pthBased on V1.2;more naturalrestoration results; better results on very low-quality / high-quality inputs.V1.2GFPGANCleanv1-NoCE-C2.pthNo colorization; no CUDA extensions are required. Trained with more data with pre-processing.V1GFPGANv1.pthThe paper model, with colorization.The comparisons are inComparisons.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.VersionStrengthsWeaknessesV1.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 identityV1.2✓ sharper output✓ with beauty makeup✗ some outputs are unnaturalYou can findmore models (such as the discriminators)here: [Google Drive], OR [Tencent Cloud 腾讯微云]:computer: TrainingWe provide the training codes for GFPGAN (used in our paper).You could improve it according to your own needs.TipsMore high quality faces can improve the restoration quality.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.)Dataset preparation:FFHQDownload pre-trained models and other data. Put them in theexperiments/pretrained_modelsfolder.Pre-trained StyleGAN2 model: StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pthComponent locations of FFHQ: FFHQ_eye_mouth_landmarks_512.pthA simple ArcFace model: arcface_resnet18.pthModify the configuration fileoptions/train_gfpgan_v1.ymlaccordingly.Trainingpython -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 AcknowledgementGFPGAN 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: ContactIf you have any question, please emailxintao.wang@outlook.comorxintaowang@tencent.com.