图片上色(有demo体验)

image.png

早期的老照片都是黑白的,通过AI技术能自动给它们上色,先来看下原理。

原理

基本原理就是encoder-decoder架构,然后加上一些GAN training技巧,可以使得生成的图片更加真实。代码可见https://github.com/jantic/DeOldify​github.com

值得一提的是,这里用的不是传统的GAN,传统GAN会把Generator和Discriminator放到一起end2end train,这里用了一种称之为"NoGAN"的技巧,这种技巧能使得生成的图片更少的局部瑕疵。具体步骤如下

The steps are as follows: First train the generator in a conventional way by itself with just the feature loss. Next, generate images from that, and train the critic on distinguishing between those outputs and real images as a basic binary classifier. Finally, train the generator and critic together in a GAN setting (starting right at the target size of 192px in this case). Now for the weird part: All the useful GAN training here only takes place within a very small window of time. There's an inflection point where it appears the critic has transferred everything it can that is useful to the generator. Past this point, image quality oscillates between the best that you can get at the inflection point, or bad in a predictable way (orangish skin, overly red lips, etc). There appears to be no productive training after the inflection point. And this point lies within training on just 1% to 3% of the Imagenet Data! That amounts to about 30-60 minutes of training at 192px.

1. 训练Generator
2. 用Generator生成图片
3. 训练Discriminator区分生成图片和实际图片
4. Generator和Discriminator一起e2e finetune
5. 当Discriminator已经把Generator所有的信息都迁移过来了(达到了所谓的inflection point,过了这个点效果反而下降),就停止,然后回到第一步重复迭代

具体为啥要分开训练Generator和Discriminator,目前尚不清楚,但是事实就是在上色这个任务上就是很work。

Keep in mind- I haven't been entirely rigorous in figuring out what all is going on in NoGAN- I'll save that for a paper. That means there's a good chance I'm wrong about something. But I think it's definitely worth putting out there now because I'm finding it very useful- it's solving basically much of my remaining problems I had in DeOldify.

我这边做了一个微信公众号的API调用接口,方便大家来试用。关注公众号 LeetCode总结 ,二维码被吞的话可以直接在微信里面搜索公众号名称

image.png

后台直接发送你要转化的图片即可。比如

image

点进去就可以看到上色后的结果

image

欢迎大家试用,过年在家串不了门,不如把之前的老照片翻出来试一下上色吧!

PS:上色的程度设置的25,太大了的话机器容易响应不过来,大家见谅,后续需要的话我可以买一台强劲一点的阿里云服务器。

你可能感兴趣的:(图片上色(有demo体验))