• Stars
    star
    128
  • Rank 272,495 (Top 6 %)
  • Language
    Python
  • Created almost 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is the code for "Machine Learning API tutorial" By Siraj Raval on Youtube

Fast Style Transfer in TensorFlow

Add styles from famous paintings to any photo in a fraction of a second! You can even style videos!

It takes 100ms on a 2015 Titan X to style the MIT Stata Center (1024×680) like Udnie, by Francis Picabia.

Our implementation is based off of a combination of Gatys' A Neural Algorithm of Artistic Style, Johnson's Perceptual Losses for Real-Time Style Transfer and Super-Resolution, and Ulyanov's Instance Normalization.

Running on FloydHub

It is very easy to train, evaluate and serve fast style transfer on [Floydhub][https://www.floydhub.com/]. Follow the instructions below:

  1. Visit Floydhub site to create an account if you do not have one.
  2. Clone this repository to your machine.
  3. Run floyd init <project name> inside the directory.

Now you can:

  1. Train a new model
  2. Evaluate an existing model
  3. Serve a trained model at a public API.

Video Stylization

Here we transformed every frame in a video, then combined the results. Click to go to the full demo on YouTube! The style here is Udnie, as above.

See how to generate these videos here!

Image Stylization

We added styles from various paintings to a photo of Chicago. Click on thumbnails to see full applied style images.



Implementation Details

Our implementation uses TensorFlow to train a fast style transfer network. We use roughly the same transformation network as described in Johnson, except that batch normalization is replaced with Ulyanov's instance normalization, and the scaling/offset of the output tanh layer is slightly different. We use a loss function close to the one described in Gatys, using VGG19 instead of VGG16 and typically using "shallower" layers than in Johnson's implementation (e.g. we use relu1_1 rather than relu1_2). Empirically, this results in larger scale style features in transformations.

Documentation

Training Style Transfer Networks

Use style.py to train a new style transfer network. Run python style.py to view all the possible parameters. Training takes 4-6 hours on a Maxwell Titan X. More detailed documentation here. Before you run this, you should run setup.sh. Example usage:

python style.py --style path/to/style/img.jpg \
  --checkpoint-dir checkpoint/path \
  --test path/to/test/img.jpg \
  --test-dir path/to/test/dir \
  --content-weight 1.5e1 \
  --checkpoint-iterations 1000 \
  --batch-size 20

To Train on Floyd

Run style.py like you would normally would. The input data generated by setup.sh is available as a Floyd Data source.

floyd run --data <vgg_and_training_data_source> "python style.py --style path/to/style/img.jpg \
  --checkpoint-dir /output \
  --test path/to/test/img.jpg \
  --test-dir path/to/test/dir \
  --content-weight 1.5e1 \
  --checkpoint-iterations 1000 \
  --batch-size 20"

Remember: floyd command uploads contents of your current directory. So use relative paths only. '/output' is a special path. Contents stored here will be saved after the training is done. So checkpoints should be directed there.

Evaluating Style Transfer Networks

Use evaluate.py to evaluate a style transfer network. Run python evaluate.py to view all the possible parameters. Evaluation takes 100 ms per frame (when batch size is 1) on a Maxwell Titan X. More detailed documentation here. Takes several seconds per frame on a CPU. Models for evaluation are located here. Example usage:

python evaluate.py --checkpoint path/to/style/model.ckpt \
  --in-path dir/of/test/imgs/ \
  --out-path dir/for/results/

To evaluate on Floyd

floyd run --data <output_id_of_training> "python evaluate.py --checkpoint /input/model.ckpt \
  --in-path dir/of/test/imgs/ \
  --out-path dir/for/results/"

Remember: '/input' is a special path. Any data source included in the run command will be available at that path.

Stylizing Video

Use transform_video.py to transfer style into a video. Run python transform_video.py to view all the possible parameters. Requires ffmpeg. More detailed documentation here. Example usage:

python transform_video.py --in-path path/to/input/vid.mp4 \
  --checkpoint path/to/style/model.ckpt \
  --out-path out/video.mp4 \
  --device /gpu:0 \
  --batch-size 4

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

Floyd requirements are specified in the floyd_requirements.txt file. They will be installled before running your code.

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.

More Repositories

1

Learn_Machine_Learning_in_3_Months

This is the code for "Learn Machine Learning in 3 Months" by Siraj Raval on Youtube
7,557
star
2

learn_math_fast

This is the Curriculum for "How to Learn Mathematics Fast" By Siraj Raval on Youtube
Python
3,183
star
3

Learn_Data_Science_in_3_Months

This is the Curriculum for "Learn Data Science in 3 Months" By Siraj Raval on Youtube
2,701
star
4

Learn_Deep_Learning_in_6_Weeks

This is the Curriculum for "Learn Deep Learning in 6 Weeks" by Siraj Raval on Youtube
2,680
star
5

Learn_Computer_Science_in_5_Months

This is the Curriculum for "Learn Computer Science in 5 Months" By Siraj Raval on Youtube
1,856
star
6

Learn_Blockchain_in_2_months

This is the code for "Learn Blockchain in 2 Months" by Siraj Raval on Youtube
1,725
star
7

YOLO_Object_Detection

This is the code for "YOLO Object Detection" by Siraj Raval on Youtube
Python
1,687
star
8

tensorflow_chatbot

Tensorflow chatbot demo by @Sirajology on Youtube
Python
1,422
star
9

Learn_Computer_Vision

This is the curriculum for "Learn Computer Vision" by Siraj Raval on Youtube
1,078
star
10

Learn-Natural-Language-Processing-Curriculum

This is the curriculum for "Learn Natural Language Processing" by Siraj Raval on Youtube
1,054
star
11

Machine_Learning_Journey

This is the Curriculum for "Machine Learning Journey" By Siraj Raval on Youtube
973
star
12

deepfakes

This is the code for "DeepFakes" by Siraj Raval on Youtube
Python
946
star
13

100_Days_of_ML_Code

These are the instructions for "100 Days of ML Code" By Siraj Raval on Youtube
865
star
14

How-to-Predict-Stock-Prices-Easily-Demo

How to Predict Stock Prices Easily - Intro to Deep Learning #7 by Siraj Raval on Youtube
Jupyter Notebook
764
star
15

Programming_Interview_Study_Plan

This is the Programming Interview Study Plan by Siraj Raval on Youtube
689
star
16

Reinforcement_Learning_for_Stock_Prediction

This is the code for "Reinforcement Learning for Stock Prediction" By Siraj Raval on Youtube
Python
610
star
17

ChatGPT_Trading_Bot

This is the code for the "ChatGPT Trading Bot" Video by Siraj Raval on Youtube
Jupyter Notebook
587
star
18

capsule_networks

This is the code for "Capsule Networks: An Improvement to Convolutional Networks" by Siraj Raval on Youtube
Python
569
star
19

tensorflow_image_classifier

TensorFlow Image Classifier Demo by @Sirajology on Youtube
Python
530
star
20

Make_Money_with_Tensorflow_2.0

This is the code for "Make Money with Tensorflow 2.0" by Siraj Raval
Jupyter Notebook
527
star
21

LearnML

This is the Study Guide for Learn Machine Learning in 3 Months (PyTorch Curriculum) by Siraj Raval on Youtube
520
star
22

Mathematics_for_Beginners

This is the formula sheet for "Mathematics for Beginners" by Siraj Raval on Youtube
484
star
23

How_to_make_a_text_summarizer

This is the code for "How to Make a Text Summarizer - Intro to Deep Learning #10" by Siraj Raval on Youtube
Jupyter Notebook
481
star
24

Pokemon_GAN

This is the code for "Generating Pokemon with a Generative Adversarial Network" by Siraj Raval on Youtube
Python
432
star
25

Watch-Me-Build-a-Trading-Bot

This is the code for "Watch Me Build a Trading Bot" by Siraj Raval on Youtube
JavaScript
419
star
26

Learn_Physics_in_2_Months

This is the curriculum for "Learn Physics in 2 Months" by Siraj Raval on Youtube
414
star
27

How_to_simulate_a_self_driving_car

This is the code for "How to Simulate a Self-Driving Car" by Siraj Raval on Youtube
Python
413
star
28

Your_First_Decentralized_Application

This is the code for "A Guide to Building Your First Decentralized Application" by Siraj Raval on Youtube
Jupyter Notebook
413
star
29

AI_in_Finance

This is the code for "AI in Finance" By Siraj Raval on Youtube
JavaScript
410
star
30

The_Math_of_Intelligence

This is the Syllabus for Siraj Raval's new course "The Math of Intelligence"
394
star
31

tensorflow_speech_recognition_demo

This is the code for 'How to Make a Simple Tensorflow Speech Recognizer' by @Sirajology on Youtube
Python
383
star
32

Convolutional_neural_network

This is the code for "Convolutional Neural Networks - The Math of Intelligence (Week 4)" By Siraj Raval on Youtube
Jupyter Notebook
368
star
33

AI_Startup_Prototype

This is the code for "Watch Me Build an AI Startup" By Siraj Raval on Youtube
Python
364
star
34

Neural_Network_Voices

This is the code for "Neural Network Voices" by Siraj Raval on Youtube
Python
358
star
35

A_Guide_to_Running_Tensorflow_Models_on_Android

This is the code for"A Guide to Running Tensorflow Models on Android" By SIraj Raval on Youtube
Java
344
star
36

pose_estimation

This is the code for "Webcam Tracking with Tensorflow.js" By Siraj Raval on Youtube
TypeScript
318
star
37

Everybody_Dance_Now

This is the code for "Everybody Dance Now!" By Siraj Raval on Youtube
Python
313
star
38

Q-Learning-for-Trading

Python
311
star
39

ethereum_future

This is the Code for "Ethereum Future Prices" by Siraj Raval on Youtube
Jupyter Notebook
299
star
40

How-to-Use-GitHub

This is the supplementary material for "How to Use GitHub" By Siraj Raval on Youtube
294
star
41

AI_Composer

AI Composer for Machine Learning for Hackers #2
Python
294
star
42

how_to_deploy_a_keras_model_to_production

This is the code for the "How to Deploy a Keras Model to Production" by Siraj Raval on Youtube
Python
288
star
43

predicting_stock_prices

This is the coding challenge for "Predicting Stock Prices" by @Sirajology on Youtube
Python
282
star
44

How-to-Deploy-a-Tensorflow-Model-in-Production

This is the code for the "How to Deploy a Tensorflow Model in Production" by Siraj Raval on YouTube
Python
280
star
45

linear_regression_live

This is the code for the "How to Do Linear Regression the Right Way" live session by Siraj Raval on Youtube
Python
269
star
46

Chatbot-AI

Chatbot AI for Machine Learning for Hackers #6
Lua
261
star
47

Predicting_Winning_Teams

This is the code for "Predicting the Winning Team with Machine Learning" by Siraj Raval on Youtube
Jupyter Notebook
249
star
48

Music_Generator_Demo

Music Generator Demo by @Sirajology on Youtube
Python
246
star
49

Data_Science_Interview_Guide

These are the tips for "5 Steps to Pass Data Science Interviews" By Siraj Raval on Youtube
245
star
50

quantum_machine_learning

This is the code for "Quantum Machine Learning" By Siraj Raval on Youtube
HTML
245
star
51

AI_Freelancing

This is the code for "How to Do Freelance AI Programming" By Siraj Raval on Youtube
245
star
52

AI_Artist

AI Artist for Machine Learning for Hackers #5
Python
237
star
53

bitcoin_prediction

This is the code for "Bitcoin Prediction" by Siraj Raval on Youtube
Jupyter Notebook
234
star
54

tensorflow_demo

Tensorflow Demo for my TF in 5 Min Video on Youtube
Python
227
star
55

Neural_Differential_Equations

This is the code for "Neural DIfferential Equations" By Siraj Raval on Youtube
Jupyter Notebook
225
star
56

Stock_Market_Prediction

This is the code for "Stock Market Prediction" by Siraj Raval on Youtube
Jupyter Notebook
218
star
57

Build-an-AI-Startup-with-PyTorch

This is the code for 'Build an AI Startup with Pytorch" by Siraj Raval
Java
217
star
58

ChatGPT_Sports_Betting_Bot

This is the code for "I Built a Sports Betting Bot with ChatGPT" by Siraj Raval on Youtube
Jupyter Notebook
216
star
59

Move_37_Syllabus

This is the syllabus for "Move 37", Siraj Raval's new course at School of AI
216
star
60

Classifying_Data_Using_a_Support_Vector_Machine

This is the code for the "Classifying Data using Gradient Descent" by Siraj Raval on Youtube
Jupyter Notebook
212
star
61

A-Guide-to-DeepMinds-StarCraft-AI-Environment

This is the code for "A Guide to DeepMind's StarCraft AI Environment" by Siraj Raval on Youtube
Python
210
star
62

Landing-a-SpaceX-Falcon-Heavy-Rocket

This is the code for "Landing a SpaceX Falcon Heavy Rocket" By Siraj Raval on Youtube
Python
209
star
63

How_to_Build_a_healthcare_startup

This is the code for "How to Build a Healthcare Startup" by Siraj Raval on Youtube
Dart
203
star
64

AI_For_Music_Composition

This is the code for "AI for Music Composition" by Siraj Raval on Youtube
Python
202
star
65

How_to_make_a_chatbot

This is the code for "How to Make a Chatbot - Intro to Deep Learning #12' by Siraj Raval on YouTube
Python
199
star
66

LSTM_Networks

This is the code for "LSTM Networks - The Math of Intelligence (Week 8)" By Siraj Raval on Youtube
Jupyter Notebook
194
star
67

Make_a_neural_network

This is the code for the "Make a Neural Network" - Intro to Deep Learning #2 by Siraj Raval on Youtube
Python
193
star
68

AI_For_Business_Curriculum

This is the curriculum for the "AI for Business" Course By Siraj Raval on Youtube
189
star
69

Time_Series_Prediction

This is the code for "Time Series Prediction" By Siraj Raval on Youtube
Jupyter Notebook
187
star
70

3D_Pose_Estimation

This is the code for "Machine Vision" By Siraj Raval on Youtube
Python
185
star
71

Financial_Forecasting_with_TensorflowJS

This is the code for "Financial Forecasting with Tensorflow.js" By Siraj Raval on Youtube
JavaScript
184
star
72

linear_regression_demo

This is the code for "How to Make a Prediction - Intro to Deep Learning #1' by Siraj Raval on YouTube
Python
182
star
73

ethereum_demo

This is the code for "Ethereum Explained" by Siraj Raval on Youtube
Jupyter Notebook
178
star
74

chatbot_tutorial

This is the code for "Chatbot Tutorial" by Siraj Raval on Youtube
Python
176
star
75

Watch-Me-Build-a-Finance-Startup

This is the code for "Watch Me Build a Finance Startup" by Siraj Raval on Youtube
Java
172
star
76

word_vectors_game_of_thrones-LIVE

This is the code for the "How to Make Word Vectors from Game of Thrones (LIVE) " Siraj Raval on Youtube
Jupyter Notebook
170
star
77

AI_in_Medicine_Clinical_Imaging_Classification

This is the code for "AI in Medicine " By Siraj Raval on Youtube
Python
165
star
78

deep_q_learning

This is the Code for "Deep Q Learning - The Math of Intelligence #9" By Siraj Raval on Youtube
Jupyter Notebook
163
star
79

AI_Writer

AI Writer for Machine Learning for Hackers #8
Python
163
star
80

Bitcoin_Trading_Bot

This is the code for "Bitcoin Trading Bot" By Siraj Raval on Youtube
Jupyter Notebook
163
star
81

Unity_ML_Agents

This is the code for "Unity AI" by Siraj Raval on Youtube
Python
161
star
82

how_to_convert_text_to_images

This is the code for "How to Convert Text to Images - Intro to Deep Learning #16' by Siraj Raval on YouTube
Python
155
star
83

Game-AI

Game AI for Machine Learning for Hackers #3
Python
154
star
84

Intro_to_the_Math_of_intelligence

This is the code for "Intro - The Math of Intelligence" by Siraj Raval on Youtube
Python
152
star
85

Sentiment_Analysis

This is the code for "Sentiment Analysis - Data Lit #1" by Siraj Raval on Youtube
Jupyter Notebook
151
star
86

recommender_live

Jupyter Notebook
149
star
87

recurrent_neural_network

This is the code for "Recurrent Neural Networks - The Math of Intelligence (Week 5)" By Siraj Raval on Youtube
Jupyter Notebook
147
star
88

How-to-Learn-from-Little-Data

This is the code for "How to Learn from Little Data - Intro to Deep Learning #17' by Siraj Raval on YouTube
Python
144
star
89

How_to_generate_music_in_tensorflow_LIVE

Python
140
star
90

Kaggle_Earthquake_challenge

This is the code for the Kaggle Earthquake Challenge by Siraj Raval on Youtube
Jupyter Notebook
139
star
91

OpenAI_Five_vs_Dota2_Explained

This is the code for "OpenAI Five vs DOTA 2 Explained" By Siraj Raval on Youtube
Python
138
star
92

Learn_Synthetic_Biology

137
star
93

How-to-Build-a-Biomedical-Startup

This is the code for "How to Build a Biomedical Startup" by Siraj Raval on Youtube
Dart
134
star
94

Gaussian_Mixture_Models

This is the code for "Gaussian Mixture Models - The Math of Intelligence (Week 7)" By Siraj Raval on Youtube
Jupyter Notebook
134
star
95

Make_Money_with_Tensorflow

This is the code for "Make Money with Tensorflow" by Siraj Raval on Youtube
Python
129
star
96

AI_Supply_Chain

This is the code for "AI for Supply Chain" by Siraj Raval on Youtube
Jupyter Notebook
128
star
97

how_to_build_a_bitcoin_startup

This is the code for "How to Build a Bitcoin Startup" by Siraj Raval on Youtube
JavaScript
126
star
98

machine_learning_and_neuroscience

This is the code for "Machine Learning & Neuroscience" By Siraj Raval on Youtube
JavaScript
123
star
99

k_means_clustering

This is the code for "K-Means Clustering - The Math of Intelligence (Week 3)" By SIraj Raval on Youtube
Jupyter Notebook
122
star
100

alphago_demo

This is the code for "How Does DeepMind's AlphaGo Zero Work?" Siraj Raval on Youtube
Python
120
star