fast-style-transfer

TensorFlow CNN for fast style transfer ⚡🖥🎨🖼

https://github.com/lengstrom/fast-style-transfer

Science Score: 64.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • ✓
    CITATION.cff file
    Found CITATION.cff file
  • ✓
    codemeta.json file
    Found codemeta.json file
  • ✓
    .zenodo.json file
    Found .zenodo.json file
  • â—‹
    DOI references
  • ✓
    Academic publication links
    Links to: arxiv.org
  • ✓
    Committers with academic emails
    1 of 16 committers (6.3%) from academic institutions
  • â—‹
    Institutional organization owner
  • â—‹
    JOSS paper metadata
  • â—‹
    Scientific vocabulary similarity
    Low similarity (8.2%) to scientific vocabulary

Keywords

deep-learning neural-networks neural-style style-transfer
Last synced: 6 months ago · JSON representation ·

Repository

TensorFlow CNN for fast style transfer ⚡🖥🎨🖼

Basic Info
  • Host: GitHub
  • Owner: lengstrom
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 10.8 MB
Statistics
  • Stars: 10,958
  • Watchers: 316
  • Forks: 2,595
  • Open Issues: 111
  • Releases: 0
Topics
deep-learning neural-networks neural-style style-transfer
Created over 9 years ago · Last pushed over 2 years ago
Metadata Files
Readme Funding Citation

README.md

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.

Sponsorship

Please consider sponsoring my work on this project!

License

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

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.

Stylized fox video. Click to go to YouTube!

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.

Virtual Environment Setup (Anaconda) - Windows/Linux

Tested on | Spec | | |-----------------------------|-------------------------------------------------------------| | Operating System | Windows 10 Home | | GPU | Nvidia GTX 2080 TI | | CUDA Version | 11.0 | | Driver Version | 445.75 |

Step 1:Install Anaconda

https://docs.anaconda.com/anaconda/install/

Step 2:Build a virtual environment

Run the following commands in sequence in Anaconda Prompt: conda create -n tf-gpu tensorflow-gpu=2.1.0 conda activate tf-gpu conda install jupyterlab jupyter lab Run the following command in the notebook or just conda install the package: !pip install moviepy==1.0.2 Follow the commands below to use fast-style-transfer

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

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/

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

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

Related Work

Owner

  • Name: Logan Engstrom
  • Login: lengstrom
  • Kind: user
  • Location: Cambridge, MA
  • Company: MIT

CS PhD student at @MIT

Citation (CITATION.cff)

# YAML 1.2
---
authors: 
  -
    family-names: Engstrom
    given-names: Logan
cff-version: "1.1.0"
date-released: 2016-10-31
message: "If you use this software, please cite it using these metadata."
repository-code: "https://github.com/lengstrom/fast-style-transfer"
title: "Fast Style Transfer"
version: "1.0"
...

GitHub Events

Total
  • Watch event: 107
  • Issue comment event: 1
  • Pull request event: 2
  • Fork event: 13
Last Year
  • Watch event: 107
  • Issue comment event: 1
  • Pull request event: 2
  • Fork event: 13

Committers

Last synced: 10 months ago

All Time
  • Total Commits: 52
  • Total Committers: 16
  • Avg Commits per committer: 3.25
  • Development Distribution Score (DDS): 0.577
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Logan Engstrom e****m@m****u 22
Jonathan Böcker j****r@g****m 5
zhujinchang s****u@g****m 4
Emmanuel Ariza e****a@g****m 3
Fergal Cotter f****0@g****m 3
Christoph Bonitz m****z@g****m 2
David Fisher t****n@g****m 2
Max Woolf m****x@m****m 2
naveen-annam 3****m 2
Andrew Murray r****e@g****m 1
Drake Rehfeld d****d 1
Feber f****o@g****m 1
Lupino l****u@g****m 1
Neutrino 1****6@q****m 1
Wael Boutglay b****l@g****m 1
van-burgerberg 5****g 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 10 months ago

All Time
  • Total issues: 157
  • Total pull requests: 41
  • Average time to close issues: 2 months
  • Average time to close pull requests: 6 months
  • Total issue authors: 135
  • Total pull request authors: 39
  • Average comments per issue: 2.6
  • Average comments per pull request: 1.34
  • Merged pull requests: 13
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • michaelhuang74 (5)
  • pamruta (3)
  • spot92 (3)
  • Yagun (3)
  • suke27 (2)
  • jadonalam (2)
  • techninja (2)
  • minimaxir (2)
  • beraybentesen (2)
  • ghost (2)
  • lengstrom (2)
  • moldach (2)
  • beinando (2)
  • ArtlyStyles (2)
  • MrZoidberg (2)
Pull Request Authors
  • Schwusch (2)
  • lightning-zgc (2)
  • papajo (1)
  • dragona (1)
  • MrZoidberg (1)
  • tibbon (1)
  • willmeyers (1)
  • Ali-Parandeh (1)
  • ericguizzo (1)
  • jpalmieri (1)
  • duckladydinh (1)
  • radarhere (1)
  • maitek (1)
  • SeguinBe (1)
  • elmarhaussmann (1)
Top Labels
Issue Labels
Pull Request Labels