neural-style、chainer-fast-neuralstyle图像风格转换实验

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WoPawn/article/details/52781426

首先说明,该篇博客是在ubuntu16.04+gtx1060+cuda8.0+tensorflow源码安装、测试经历基础上进行实验,gtx 1060显卡驱动、cuda、cudnn和tensorflow安装这里不再赘述。

本实验分为neural-style和chainer-fast-neuralstyle两部分。


废话不多说,上车吧,少年

一、neural-style

  1. 载入源码,终端输入
    git clone https://github.com/anishathalye/neural-style

  2. 下载vgg19模型
    下载地址:http://www.vlfeat.org/matconvnet/models/beta16/imagenet-vgg-verydeep-19.mat

  3. 把vgg19模型放到neural-style的文件夹根目录下,如图所示
    这里写图片描述

  4. 把想转换风格的照片放入example目录,并在终端输入
    cd neural_style\
    python neural_style.py --content ./examples/1in.jpg --styles ./examples/1-style.jpg --output ./examples/1out.jpg

    其中,1in.jpg是example目录下想要转换的图片;1-style.jpg是example目录下想要模仿其风格的模板图片;1out.jpg是即将在example目录下转换生成的图片名称。

    转换过程如图所示(不清楚的图片右键新标签页打开图片):
    这里写图片描述
    这里列出两种风格转换结果
    这里写图片描述

    这里写图片描述

    这里写图片描述

    这里写图片描述

    二、chainer-fast-neuralstyle

    虽然neural-style效果已经挺不错,但其运行时间却不尽人意,gtx1060上运行一张1280×960的150k左右图片却要花费将近18分钟,而chainer-fast-neuralstyle是neural-style高效版本,运行效率大大提升,gtx1060上运行一张1280×960的150k左右图片平均时间22秒。

    1. 载入源码,终端输入
      git clone --recursive https://github.com/yusuketomoto/chainer-fast-neuralstyle

    2. 载入更多模型,终端输入
      git clone --recursive https://github.com/gafr/chainer-fast-neuralstyle-models
      此下载的文件有两个用途:
      ①复制chainer-fast-neuralstyle-models\images\目录下所有含有style字样的图片到neural_style\examples\目录下,增加neural_style可用的模板集;

      ②复制chainer-fast-neuralstyle-models\models\目录下所有model到chainer-fast-neuralstyle\models\目录下,增加chainer-fast-neuralstyle可用的模型;

    3. 安装依赖
      sudo pip install chainer

    4. 图像风格转换
      终端输入python generate.py sample_images/1.jpg -m models/candy_512_2_49000.model -o sample_images/1out.jpg
      其中,1.jpg是sample_images目录下想要转换的图片; candy_512_2_49000.model是models目录下任意一种模型; 1out.jpg是即将在sample_images目录下转换生成的图片名称。

      转换过程如图所示:
      这里写图片描述
      这里列出两种风格转换结果
      这里写图片描述

      这里写图片描述

      这里写图片描述

      这里写图片描述



猜你喜欢

转载自blog.csdn.net/WoPawn/article/details/52781426