代码拉取完成,页面将自动刷新
'''
@paper: GAN Prior Embedded Network for Blind Face Restoration in the Wild (CVPR2021)
@author: yangxy (yangtao9009@gmail.com)
'''
import os
import cv2
import glob
import time
import numpy as np
from PIL import Image
import __init_paths
from face_model.face_gan import FaceGAN
class FaceColorization(object):
def __init__(self, base_dir='./', size=1024, model=None, channel_multiplier=2):
self.facegan = FaceGAN(base_dir, size, model, channel_multiplier)
# make sure the face image is well aligned. Please refer to face_enhancement.py
def process(self, gray):
# colorize the face
out = self.facegan.process(gray)
return out
if __name__=='__main__':
model = {'name':'GPEN-Colorization-1024', 'size':1024}
indir = 'examples/grays'
outdir = 'examples/outs-colorization'
os.makedirs(outdir, exist_ok=True)
facecolorizer = FaceColorization(size=model['size'], model=model['name'], channel_multiplier=2)
files = sorted(glob.glob(os.path.join(indir, '*.*g')))
for n, file in enumerate(files[:]):
filename = os.path.basename(file)
grayf = cv2.imread(file, cv2.IMREAD_GRAYSCALE)
grayf = cv2.cvtColor(grayf, cv2.COLOR_GRAY2BGR) # channel: 1->3
colorf = facecolorizer.process(grayf)
grayf = cv2.resize(grayf, colorf.shape[:2])
cv2.imwrite(os.path.join(outdir, '.'.join(filename.split('.')[:-1])+'.jpg'), np.hstack((grayf, colorf)))
if n%10==0: print(n, file)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。