Giter VIP home page Giter VIP logo

neural_style's Introduction

Neural Style

fast style transfer with mxnet, can do videos

Setup

  • Install skimage via pip: sudo pip install scikit-image
  • Install CUDA and Cudnn v4(this repo doesn't work with Cudnn v5)
  • Install OpenCV (if you want to transfer video)
  • Install Mxnet
  • Clone this repo
  • Download models from this page and put them in models folder.

Usage

  • Open python console
>> import make_image 
>> make_image.make_image(path_to_image, style_name, output_path)

This will keep the image with its original size. For example, if you downloaded model9.pkl, make_image.make_image('test_pics/city.jpg', '9', 'out/9_city.jpg') will give you something like this alt text

If your GPU memory is limited, you can restrict the size of the input image to a fixed value. For example, make_image.make_image('test_pics/city.jpg', '9', 'out/small_9_city.jpg', (512, 512)) will first crop and resize the input image to 512x512, and give you some thing like this alt text

For more result, see this gallary or this

Transfer Video

  • Open python console
>> import make_video
>> make_video.make_video(video_name, start_time, end_time, frame_interval, style_name, output_name)

For example, if myvideo.mp4 is a 24fps video file, make_video.make_video('myvideo.mp4', 10, 30, 3, '5', 'out.gif') will select the 10sec~30sec part of the video, and the output file will be in 8fps. If you want to save to video file format, you have to install ffmpeg and build opencv with it. Or you can just save with GIF and convert it with other software. This is the website I use for converting GIF to MP4.

Here is an example result. It's small and low-fps because otherwise the GIF file will go larger than 50MB. alt text

High resolution result with higher fps can be downloaded here and here.

Speed and Memory

Image with normal size should be transfered in 1~2 second. It takes 1G GPU memory to transform a 512x512 image. It takes 4.5G GPU memory to transform a 1920x1080 image. Some models are simpler than others so they use less GPU memory.

It takes me 50 seconds to transfer the 30 seconds 800x352 8fps video above.

Please notice that the first run will be very slow because it may take a lot of time for mxnet to allocate memory and that's why I recommand using a python console so the GPU memory can be reused.

Reference

  • This repo is based on texture net, with changes.
  • This example is a good tutorial for building non-feedforward networks with mxnet.
  • images2gif comes from images2gif but the original version has error.

neural_style's People

Contributors

zhaw avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.