欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > GFPGAN - 腾讯开源的图形修复算法修复算法

GFPGAN - 腾讯开源的图形修复算法修复算法

2025/2/23 12:07:09 来源:https://blog.csdn.net/puterkey/article/details/145279020  浏览:    关键词:GFPGAN - 腾讯开源的图形修复算法修复算法

GFPGAN是腾讯开源的人脸修复算法,它利用预先训练好的面部修复算法,并且封装了各种丰富多样的先验因素进行盲脸(blind face) 修复,可以对老照片进行很好的修复。

35800 Stars 5900 Forks 345 Issues 11 贡献者 Apache License Python 语言

代码: https://github.com/TencentARC/GFPGAN

更多AI开源软件:AI开源 - 小众AI

主要功能

  • 盲修复能力:GFPGAN不需要对特定图像有任何先验知识,可以实现真正的盲修复。它利用预训练人脸GAN(如StyleGAN2)中蕴含的丰富和多样化的先验知识,来指导人脸修复过程。这种方法可以有效修复各种退化的人脸图像,如低质量、老旧或AI生成的人脸图像。
  • 身份一致性保持:在修复过程中,GFPGAN能够保持人脸的身份一致性,使得修复后的图像与原图在人脸特征上保持一致。
  • 非人脸区域增强:除了人脸区域外,GFPGAN还支持对非人脸区域(如背景)进行增强,提升整体图像的视觉效果。
  • 低分辨率图像提升:对于低分辨率的人脸图像,GFPGAN能够将其转换为高分辨率图像,提高图像的清晰度。
  • 去噪与去模糊:针对含有噪声或模糊的人脸图像,GFPGAN可以进行有效的去噪和去模糊处理,使图像更加清晰。

安装使用

依赖
  • Python >= 3.7 (建议使用 Anaconda 或 Miniconda)
  • PyTorch >= 1.7
  • 选项:NVIDIA GPU + CUDA
  • 选项:Linux
安装

我们现在提供了一个*干净的* GFPGAN 版本,它不需要定制的 CUDA 扩展。
如果您想使用我们论文中的原始模型,请参见 PaperModel.md 进行安装。

  1. 克隆存储库

    git clone https://github.com/TencentARC/GFPGAN.git
    cd GFPGAN
    
  2. 安装依赖软件包

    # Install basicsr - https://github.com/xinntao/BasicSR
    # We use BasicSR for both training and inference
    pip install basicsr# Install facexlib - https://github.com/xinntao/facexlib
    # We use face detection and face restoration helper in the facexlib package
    pip install facexlibpip 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
    
快速推理

我们以 v1.3 版本为例。更多型号可在此处找到。

下载预训练模型:GFPGANv1.3.pth

wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models

推理!

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

如果您想使用我们论文中的原始模型,请参见 PaperModel.md 进行安装和推理。

训练

我们提供了 GFPGAN 的训练代码(在我们的论文中使用)。
您可以根据自己的需要对其进行改进。

提示

  1. 更高质量的人脸可以提高修复质量。
  2. 您可能需要进行一些预处理,例如美容化妆。

步骤

(您可以尝试不需要人脸组件地标的简单版本 ( )。options/train_gfpgan_v1_simple.yml​

  1. 数据集准备:FFHQ

  2. 下载预训练模型和其他数据。将它们放入文件夹中。experiments/pretrained_models​

    1. 预训练的 StyleGAN2 模型:StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth
    2. FFHQ 的组件位置:FFHQ_eye_mouth_landmarks_512.pth
    3. 一个简单的 ArcFace 模型:arcface_resnet18.pth
  3. 相应地修改配置文件。options/train_gfpgan_v1.yml​

  4. 训练

python -m torch.distributed.launch --nproc_per_node=4 --master_port=22021 gfpgan/train.py -opt options/train_gfpgan_v1.yml --launcher pytorch

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词