fast style transfer with mxnet, can do videos
- 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.
- 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
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
For more result, see this gallary or this
- 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.
High resolution result with higher fps can be downloaded here and here.
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.
- 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.