本地使用GFPGAN进行图像人脸修复

人脸修复

首先来看一下效果图

1.下载项目和权重文件

bash 复制代码
https://github.com/iptop/GFPGAN-for-Video.git

2.部署环境

根据README文件部署好环境,额外还需要:

shell 复制代码
cd GFPGAN-1.3.8
python setup.py develop

3.下载权重文件

可提前下载好权重文件(也可以等运行代码的时候,自动下载)权重文件的url:
https://ghproxy.com/https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth
https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth
https://github.com/xinntao/facexlib/releases/download/v0.2.2/parsing_parsenet.pth

下载好的权重文件放在路径./GFPGAN-for-Video/gfpgan/weights下

安利一个github文件下载加速网站:https://ghproxy.com/

4.运行代码

原代码是用来修复视频,但是我用了后没发现有啥效果,所以暂时只是用来修复图片

在./GFPGAN-for-Video/src路径下创建脚本image_enhance.py

python 复制代码
import argparse
import cv2
from utils.restorer import Restorer

def videoEnhance (image_path , output_image_path):
    restorer = Restorer()

    image = cv2.imread(image_path)
    frame = restorer.enhance(image)
    cv2.imwrite(output_image_path, frame)
    return True

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-i',
        '--input',
        type=str,
        required=True,
        metavar='请输入要处理的图片文件路径',
        help='请输入要处理的图片文件路径')

    parser.add_argument(
        '-o',
        '--output',
        type=str,
        required=True,
        metavar='请输入输出图片的路径',
        help='请输入输出图片的路径')

    args = parser.parse_args()
    videoEnhance(args.input, args.output)

if __name__ == '__main__':
    main()

运行脚本就可得到修复后的图片了

bash 复制代码
python src/image_enhance.py -i input.png -o output.png

5.网页端体验

Hugging Face网页端:https://huggingface.co/spaces/Xintao/GFPGAN

我试了下速度很慢

相关推荐
回眸&啤酒鸭3 天前
【回眸】Minicart 电商购物车核心功能落地指南
人工智能
一隅论数智3 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
默_笙3 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
AI的探索之旅3 天前
97 个 OpenCV 实例(三十):双目立体,从标定到点云
人工智能·opencv·计算机视觉
AlbertZein3 天前
Step-5-Preview 上手实测:3D 游戏、金融分析、网页设计一次跑完
人工智能·aigc
LaughingZhu3 天前
Product Hunt 每日热榜 | 2026-09-19
人工智能·深度学习·神经网络·搜索引擎·百度
qq_426003963 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
美狐美颜SDK开放平台3 天前
开发直播APP时如何接入视频美颜SDK?开发流程与注意事项
android·人工智能·计算机视觉·音视频·直播美颜sdk