项目地址:https://github.com/jantic/DeOldify
DeOldify 的核心网络框架是 GAN ,对比以前上色技术有以下几个特点:
1,老照片中的伪影在上色过程中会被消除;
2,老照片的人脸部位来说,处理后皮肤会变得更光滑;
3,呈现更详细、真实的渲染效果;
本项目中用到的权重文件比较多,一共三个:
1,Artistic 权重,会使图片上色效果 更 大胆 一些,下载地址:
https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth
2,Stable 权重,相对于 Artistic 上色效果更保守一些,下载地址:
https://www.dropbox.com/s/usf7uifrctqw9rl/ColorizeStable_gen.pth
3 ,Video 权重,此权重文件用来给视频上色,下载地址
https://data.deepai.org/deoldify/ColorizeVideo_gen.pth
权重文件下载完毕后,在项目根目录下创建一个 models 文件夹,把下载好的三个权重文件放入 models 文件夹内
安装依赖:
pip install -r requirements.txt
项目根目录shangse.py
import os,sys from DeOldify.deoldify.visualize import get_stable_image_colorizer, get_artistic_image_colorizer, get_image_colorizer import warnings warnings.filterwarnings("ignore") def colorizer(input_path, output_dir): output_path = os.path.join(output_dir, os.path.basename(input_path)) #image_colorizer = get_stable_image_colorizer() # stable稳定版 image_colorizer = get_artistic_image_colorizer() # artistic 艺术版 #image_colorizer = get_image_colorizer(root_folder=input_path, render_factor=30, artistic=True) result = image_colorizer.get_transformed_image(input_path, render_factor=30, post_process=True, watermarked=True) if result is not None: result.save(output_path, quality=95) result.close() if __name__ == '__main__': for filenamex in os.listdir('./img/'): fns = filenamex.split('.') ext = fns[len(fns) - 1] if not ext.lower() in ['jpg', 'png']: continue print(filenamex) colorizer("img/%s" % filenamex, "img/result/")
效果:
还不错,参考:https://blog.csdn.net/weixin_42512684/article/details/117376885
标签:colorizer,get,ai,image,老照片,result,https,使用,path From: https://www.cnblogs.com/xuxiaobo/p/17171323.html