Skip to content

genekogan/fast-style-transfer

 
 

Repository files navigation

fast-style-transfer webcam script

This is a fork of fast-style-transfer which has an additional script, run_webcam.py to apply style models live to a webcam stream. Go to the README of the original page for instructions on how to train your own models, apply them to images and movies, and all the original functionality of that repository.

Installation

Setting up models

Pre-trained models for Picasso, Hokusai, Kandinsky, Liechtenstein, Wu Guanzhong, Ibrahim el-Salahi, and Google Maps.

At the top of the file run_webcam.py, there are paths to model files and style images in the variable list models. They are not included in the repo because of space. If you'd like to use the pre-trained models referred to up there, these models may be downloaded from this shared folder. To train your own, refer to the original documentation.

Usage

python run_webcam.py --width 360 --disp_width 800 --disp_source 1 --horizontal 1

There are three arguments:

  • width refers to the width in pixels of the image being restyled (the webcam will be scaled down or up to this size).
  • disp_width is the width in pixels of the image to be shown on the screen. The restyled image is resized to this after being generated. Having disp_width > width lets you run the model more quickly but generate a bigger image of lesser quality.
  • disp_source is whether or not to display the content image (webcam) and corresponding style image alongside the output image (1 by default, i.e. True)
  • horizontal is whether to concatenate content/style with output image horizontally (1, which is default) or vertically (0). Only relevant if disp_source=1

You can toggle between the different models by hitting the 'a' and 's' keys on your keyboard.

Example

stylized webcam

Requirements

You will need the following to run the above:

  • TensorFlow 0.11.0
  • Python 2.7.9, Pillow 3.4.2, scipy 0.18.1, numpy 1.11.2
  • If you want to train (and don't want to wait for 4 months):
    • A decent GPU
    • All the required NVIDIA software to run TF on a GPU (cuda, etc)
  • ffmpeg 3.1.3 if you want to stylize video

Citation

  @misc{engstrom2016faststyletransfer,
    author = {Logan Engstrom},
    title = {Fast Style Transfer},
    year = {2016},
    howpublished = {\url{https://github.com/lengstrom/fast-style-transfer/}},
    note = {commit xxxxxxx}
  }

Attributions/Thanks

  • This project could not have happened without the advice (and GPU access) given by Anish Athalye.
    • The project also borrowed some code from Anish's Neural Style
  • Some readme/docs formatting was borrowed from Justin Johnson's Fast Neural Style
  • The image of the Stata Center at the very beginning of the README was taken by Juan Paulo

License

Copyright (c) 2016 Logan Engstrom. Contact me for commercial use (email: engstrom at my university's domain dot edu). Free for research/noncommercial use, as long as proper attribution is given and this copyright notice is retained.

About

fast style transfer on your webcam, with pre-trained models at

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.5%
  • Shell 0.5%