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

我试了下速度很慢

相关推荐
B站_计算机毕业设计之家3 分钟前
python舆情分析可视化系统 情感分析 微博 爬虫 scrapy爬虫技术 朴素贝叶斯分类算法大数据 计算机✅
大数据·爬虫·python·scrapy·数据分析·1024程序员节·舆情分析
B站_计算机毕业设计之家7 分钟前
基于python人脸识别系统 人脸检测 实时检测 深度学习 Dlib库 ResNet深度卷积神经网络 pyqt设计 大数据(源码)✅
python·深度学习·目标检测·计算机视觉·信息可视化·人脸识别·1024程序员节
汤姆yu15 分钟前
2026版基于python大数据的电影分析可视化系统
大数据·python·1024程序员节·电影分析可视化
大模型知识营地15 分钟前
详解 astream 方法与 stream_mode,构建高级人机交互 Agent
人工智能
Pa2sw0rd丶20 分钟前
Python 循环导入详解:为什么会导致生产环境崩溃及企业级解决方案
后端·python
梨轻巧1 小时前
Maya Python入门:创建locator、getAttr() 获取属性、setAttr() 设置属性、定位xform()
python·maya
Xxxx. .Xxxx1 小时前
Classwork 5 - Check the HTML Tags
python
知行力1 小时前
百度PaddleOCR-VL:基于0.9B超紧凑视觉语言模型,支持109种语言,性能超越GPT-4o等大模型
人工智能·百度·1024程序员节
程序员大雄学编程1 小时前
「用Python来学微积分」11. 夹逼定理与单调有界收敛定理
python·数学·微积分·1024程序员节
deephub1 小时前
vLLM 性能优化实战:批处理、量化与缓存配置方案
人工智能·python·大语言模型·1024程序员节·vllm