Coder Social home page Coder Social logo

neural-style-transfer's Introduction

Neural-Style-Transfer

A tensorflow implementation of style transfer (neural style) described in the papers:

Setup

Dependencies:

Optional (but recommended) dependencies:

After installing the dependencies:

  • Download the VGG-19 model weights (see the "VGG-VD models from the Very Deep Convolutional Networks for Large-Scale Visual Recognition project" section). More info about the VGG-19 network can be found here.
  • After downloading, copy the weights file imagenet-vgg-verydeep-19.mat to the project directory.

Usage

Basic Usage

Single Image

  1. Copy 1 content image to the default image content directory ./image_input
  2. Copy 1 or more style images to the default style directory ./styles

Note: Supported image formats include: .png, .jpg, .ppm, .pgm

  1. Run the command with specific arguments:
python neural_style_transfer.py <arguments>

Example:

python neural_style_transfer.py --content_img c1.jpg \
                                --style_imgs s1.jpg \
                                --max_size 1024 \
                                --max_iterations 100 \
                                --device /cpu:0 \
                                --verbose;

To use multiple style images, pass a space-separated list of the image names and image weights like this:

--style_imgs s1.jpg s2.jpg --style_imgs_weights 0.5 0.5

Arguments

  • --meta_name : Filename of the configuration settings
  • --content_img: Filename of the content image. Example: c1.jpg
  • --content_img_dir: Relative or absolute directory path to the content image. Default: ./image_input
  • --style_imgs: Filenames of the style images. To use multiple style images, pass a space-separated list. Example: --style_imgs s1.jpg
  • --style_imgs_weights: The blending weights for each style image. Default: 1.0 (assumes only 1 style image)
  • --style_imgs_dir: Relative or absolute directory path to the style images. Default: ./styles
  • --init_img_type: Image used to initialize the network. Default: content
  • --max_size: Maximum width or height of the input images. Default: 1920
  • --content_weight: Weight for the content loss function. Default: 5e0
  • --style_weight: Weight for the style loss function. Default: 1e4
  • --tv_weight: Weight for the total variational loss function. Default: 1e-3
  • --content_layers: Space-separated VGG-19 layer names used for the content image. Default: conv4_2
  • --style_layers: Space-separated VGG-19 layer names used for the style image. Default: relu1_1 relu2_1 relu3_1 relu4_1 relu5_1
  • --content_layer_weights: Space-separated weights of each content layer to the content loss. Default: 1.0
  • --style_layer_weights: Space-separated weights of each style layer to loss. Default: 0.2 0.2 0.2 0.2 0.2
  • --model_weights: Weights and biases of the VGG-19 network. Download here. Default:imagenet-vgg-verydeep-19.mat
  • --pooling_type: Type of pooling in convolutional neural network. Choices: avg, max. Default: avg
  • --device: GPU or CPU device. GPU mode highly recommended but requires NVIDIA CUDA. Choices: /gpu:0 /cpu:0. Default: /gpu:0
  • --img_output_dir: Directory to write output to. Default: ./image_output
  • --img_name: Filename of the output image. Default: result
  • --verbose: Boolean flag indicating if statements should be printed to the console.
  • --write_iterations_adam: Boolean flag indicating if output images should be writed in every iteration under the Adam optimizer.

Optimization Arguments

  • --optimizer: Loss minimization optimizer. L-BFGS gives better results. Adam uses less memory. Choices: lbfgs, adam. Default: lbfgs
  • --learning_rate: Learning-rate parameter for the Adam optimizer. Default: 1e0
  • --max_iterations: Max number of iterations for the Adam or L-BFGS optimizer. Default: 1000
  • --print_iterations: Number of iterations between optimizer print statements. Default: 50

References

This implementation is based on the project:

neural-style-transfer's People

Contributors

jeanpierrethach avatar

Watchers

James Cloos avatar  avatar  avatar

neural-style-transfer's Issues

Implementation

Concepts to understand

Machine Learning Coursera's by Andrew Ng
Mean squared error
Normalization, Rescaling
Cost function
Activation functions (tanh, sigmoid, etc.)
Gradient descent
Backpropagation
Optimizer function (overfitting, regularization/penalizing)
Gatys Image Style Transfer paper
Content loss function
Style loss function
Gram Matrix
  • Denoising loss function

  • Convolutional Neural Network

    1. Filtering
    2. Convolution layer
    3. Pooling layer
    4. Rectified Linear Units layer
    5. Fully connected layer

Papers

Image Style Transfer Using Convolutional Neural Networks

Preserving Color in Neural Artistic Style Transfer

Courses

Coursera's Machine Learning by Andrew Ng

CS231n Convolutional Neural Networks for Visual Recognition

Coursera's Neural Networks by Geoffrey Hinton

Other resources

Deep Learning by Ian Goodfellow, Yoshua Bengio and Aaron Courville

MOOCs, books, etc.

Tensorflow resources

Dependencies

tensorflow 1.0.0
numpy 1.12.1
python 3.x

(may be used)
opencv 3.2.0
scipy 0.18.1
pillow 4.0.0

cuda/cudnn (if running on GPU)

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.