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

我试了下速度很慢

相关推荐
字节跳动视频云技术团队4 小时前
不用自建后端,前端页面也能接入云端数据了:Pages Data SDK 正式上线
人工智能·敏捷开发
苏三的开发日记5 小时前
5 个 UI Skill 选型对照表:从需求梳理到方案汇报
人工智能
Wellijohn6 小时前
dict、tuple、dataclass 还是 slots?我把 6 种数据载体的 8 项开销全测了一遍
后端·python·性能优化
zhangfeng11336 小时前
2025–2026 国内 AI 赛事盘点:城市级黑客松 / AIGC 创作 / 硬件厂商赛事汇总
人工智能·aigc
bufengwangluo7 小时前
爬虫和调用 API 有什么区别?为什么优先选 API
python·网络爬虫·ip·api调用
Dmz丶7 小时前
前端转 AI 100 天 Day 54:RAG 项目实战(三)——多轮对话 + 会话管理
python
console.log('npc')7 小时前
Python第9课 类学习笔记,前端js语法对照
前端·python·学习
麦豆GEO7 小时前
本地生活同城服务如何做好GEO优化
人工智能·生活
邂逅and回眸7 小时前
具身智能入门:机器人是怎么学会干活的
人工智能·机器人