基于ESRGAN和GFPGAN实现人脸图像修复

1.GUI功能如下所示。

2.实现代码。

import sys
import os
import cv2
import glob
import numpy as np
import torch
import shutil
import threading
from basicsr.archs.rrdbnet_arch import RRDBNet
from ultralytics.utils import LOGGER, colorstr
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QFormLayout, QLineEdit, QPushButton, QFileDialog, QRadioButton, QCheckBox, QDoubleSpinBox, QSpinBox, QComboBox)
import warnings
warnings.filterwarnings("ignore", category=UserWarning, module="torchvision.models._utils")

def run_super_resolution(config):
    device = torch.device('cuda' if (config['device'] == 'GPU' and torch.cuda.is_available()) else 'cpu')
    if config['magnification'] == 4:
        model_path = config['model_path_x4']
    else:
        model_path = config['model_path_x2']
    model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32)
    model.load_state_dict(torch.load(model_path, map_location=device)['params'], strict=True)
    model.eval()
    model = model.to(device)
    if config['open_face_enhance']:
        from gfpgan import GFPGANer
        face_enhancer = GFPGANer(model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth', upscale=config['gfpgan_magnification'], arch='clean', channel_multiplier=2)
        gfpgan_suffix = f'_gfpgan_x{config["gfpgan_magnification"]}'
    else:
        gfpgan_suffix = ''
    if os.path.exists(config["output_folder"]):
        shutil.rmtree(config["output_folder"])
    os.makedirs(config['output_folder'], exist_ok=True)
    image_paths = sorted(glob.glob(os.path.join(config['input_folder'], '*'))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值