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

我试了下速度很慢

相关推荐
Kenneth風车10 分钟前
【机器学习(五)】分类和回归任务-AdaBoost算法-Sentosa_DSML社区版
人工智能·算法·低代码·机器学习·数据分析
凌不了云12 分钟前
windows环境下安装python第三方包
开发语言·python
AI小白龙*13 分钟前
大模型团队招人(校招):阿里巴巴智能信息,2025届春招来了!
人工智能·langchain·大模型·llm·transformer
大熊程序猿13 分钟前
python 读取excel数据存储到mysql
数据库·python·mysql
生椰拿铁You16 分钟前
Python
python
鸽芷咕18 分钟前
【Python报错已解决】python setup.py bdist_wheel did not run successfully.
开发语言·python·机器学习·bug
空指针异常Null_Point_Ex34 分钟前
大模型LLM之SpringAI:Web+AI(一)
人工智能·chatgpt·nlp
清纯世纪1 小时前
基于深度学习的图像分类或识别系统(含全套项目+PyQt5界面)
开发语言·python·深度学习
孤华暗香1 小时前
Python快速入门 —— 第三节:类与对象
开发语言·python
didiplus1 小时前
【趣学Python算法100例】百钱百鸡
python·算法·百钱百鸡