Giter Site home page Giter Site logo

xixilemon / fast-style-transfer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jxyyjm/fast-style-transfer

0.0 2.0 0.0 4.18 MB

A TensorFlow implementation of real-time style transfer based on the paper 'Perceptual Losses for Real-Time Style Transfer and Super-Resolution' by Johnson et. al

License: GNU General Public License v3.0

Python 100.00%

fast-style-transfer's Introduction

Real-Time Style Transfer

A TensorFlow implementation of real-time style transfer based on the paper Perceptual Losses for Real-Time Style Transfer and Super-Resolution by Johnson et. al.

Algorithm

See my related blog post for an overview of the algorithm for real-time style transfer.

The total loss used is the weighted sum of the style loss, the content loss and a total variation loss. This third component is not specfically mentioned in the original paper but leads to more cohesive images being generated.

Requirements

  • Python 2.7
  • TensorFlow 1.n
  • SciPy & NumPy
  • Download the pre-trained VGG network and place it in the top level of the repository (~500MB)
  • For training:
    • It is recommended to use a GPU to get good results within a reasonable timeframe
    • You will need an image dataset to train your networks. I used the Microsoft COCO dataset and resized the images to 256x256 pixels
  • Generation of styled images can be run on a CPU or GPU. Some pre-trained style networks can be download from here (~700MB)

Running the code

Training a network for a particular style

python train_network.py --style <style image> --train-path <path to training images> --save-path <directory to save network>

The algorithm will run with the following settings:

NUM_EPOCHS=5          # override with --epochs argument
BATCH_SIZE=4          # override with --batch-size argument
LEARNING_RATE = 1e-3  # override with --learning-rate argument
CONTENT_WEIGHT = 1  # override with --content-weight argument
STYLE_WEIGHT = 5    # override with --style-weight argument
TV_WEIGHT = 1e-6       # override with --tv-weight argument

To train the network using a GPU run with the --use-gpu flag.

Using a trained network to generate a style transfer

python stylize_image.py --content <content image> --network-path <network directory> --output-path <output filename>

To run the style transfer with a GPU run with the --use-gpu flag.

I have made the pre-trained networks for the 3 styles shown in the results section below available. They can be downloaded from here (~700MB).

Results

I trained three networks style transfers using the following three style images:

Style Images

Each network was trained with 80,000 training images taken from the Microsoft COCO dataset and resized to 256ร—256 pixels. Training was carried out for 100,000 iterations with a batch size of 4 and took approximately 12 hours on a GTX 1080 GPU. Using the trained network to generate style transfers took approximately 5 seconds on a CPU. Here are some of the style transfers I was able to generate:

Results

Acknowledgements

This code was inspired by an existing TensorFlow implementation by Logan Engstrom, and I have re-used most of his transform network code here. The VGG network code is based on an existing implementation by Anish Anish Athalye

License

Released under GPLv3, see LICENSE.txt

fast-style-transfer's People

Contributors

shafeentejani 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.