DeOldify使用ai来给老照片上色
项目地址: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
本文来自博客园,作者:河北大学-徐小波,转载请注明原文链接:https://www.cnblogs.com/xuxiaobo/p/17171323.html
![河北大学,徐小波,陕西宝鸡,岐山,北京通州](https://images.cnblogs.com/cnblogs_com/blogs/779648/galleries/2264184/o_230113070645_wx.jpg)