本地使用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

我试了下速度很慢

相关推荐
用户8356290780514 分钟前
使用 Python 在 Excel 中查找、替换数据并高亮显示
后端·python
GPU实战笔记8 分钟前
PyCharm 接云 GPU:远端项目连接与远程解释器别混为一谈
python·pycharm·ssh·远程开发·云gpu
自养Agent9 分钟前
MCP Server Boundary Audit Report
linux·服务器·人工智能·windows·大模型·llm
范中勤27 分钟前
Python 协程(Coroutine)通俗讲解与技术原理:从 await 挂起到 Agent 高并发
python·agent·协程·并发编程·asyncio
小李同学_LHY31 分钟前
第一章:从人工智能到大语言模型:概念梳理与关系辨析
人工智能·语言模型·自然语言处理
虎鲸不是鱼32 分钟前
【虎鲸进化论 09】活下去:自启、守护、探活
人工智能·自动化·大模型·llm·自进化agent
派小心.1 小时前
网站统计采样数据的误差核对
大数据·服务器·前端·数据库·人工智能·小程序·数据分析
TMT星球1 小时前
云从科技参编两项人工智能操作系统国家标准正式发布
人工智能·科技
johnsong1 小时前
AI 前沿日报 2026-10-14:边界渗透
人工智能
2601_966949651 小时前
如何判断实时行情数据是否已经更新?从时间戳、交易时段到行情有效性
开发语言·python·数据分析·pandas·量化交易·股票数据·quantdash