项目作者: jihoonerd

项目描述 :
📖 Paper: A Neural Algorithm of Artistic Style 🖼️
高级语言: Python
项目地址: git://github.com/jihoonerd/A-Neural-Algorithm-of-Artistic-Style.git
创建时间: 2019-11-25T10:15:40Z
项目社区:https://github.com/jihoonerd/A-Neural-Algorithm-of-Artistic-Style

开源协议:MIT License

下载


A Neural Algorithm of Artistic Style

Content Style Style Transfer
광화문1 gogh 광화문1+gogh
광화문2 gogh 광화문2+gogh
eiffel kimhongdo eiffel+oriental

This repository implements the paper: A Neural Algorithm of Artistic Style.

Features

  • Employed TensorFlow 2 with performance optimization
  • Simple structure
  • Easy to reproduce

Model Structure

As mentioned in paper, this approache make use of the VGG network. I used VGG19 structure and weight from built-in tensorflow library. (tf.keras.applications.VGG19)

nn

I used block4_conv2 as a content layer and ['block1_conv1', 'block2_conv1', 'block3_conv1', 'block4_conv1', 'block5_conv1'] as style layers. And average pooling is used instead of max pooling as noted in the paper.

Requirements

Install packages through requirements.txt.

Also, you need trained VGG19 network unless you already have it. First call VGG19 will automatically download the network. If you want to download model weight without running whole script, you can do as follow:

  1. $ python download_vgg.py

GPU Settings

Tensorflow 2 code is optimized for GPU running.

Default running environment is assumed to be CPU-ONLY. If you want to run this repo on GPU machine, just replace tensorflow to tensorflow-gpu in package lists.

How to install

virtualenv

  1. $ virtualenv venv
  2. $ source venv/bin/activate
  3. $ pip install -r requirements.txt

venv

  1. $ python3 -m venv venv
  2. $ source venv/bin/activate
  3. $ pip install -r requirements.txt

How to run

  1. $ python main.py --help
  2. usage: main.py [-h] [--content_url CONTENT_URL] [--style_url STYLE_URL]
  3. [--quick] [--train_epochs TRAIN_EPOCHS]
  4. [--log_interval LOG_INTERVAL]
  5. A Neural Algorithm of Artistic Style
  6. optional arguments:
  7. -h, --help show this help message and exit
  8. --content_url CONTENT_URL
  9. Content image url
  10. --style_url STYLE_URL
  11. Style image url
  12. --quick Set input image as the content image
  13. --train_epochs TRAIN_EPOCHS
  14. --log_interval LOG_INTERVAL

You can give custom image url to content_url and style_url arguemtns.

If you set quick, style transfer will start from your content image instead of white noise. This will give you the result much faster than starting from white noise.

Test

pytest is used for testing.

  1. ============================= test session starts ==============================
  2. platform linux -- Python 3.6.9, pytest-5.0.1, py-1.8.0, pluggy-0.13.1
  3. rootdir: /home/jihoon/Documents/A-Neural-Algorithm-of-Artistic-Style
  4. collected 3 items
  5. test/test_styletf.py ... [100%]
  6. =============================== warnings summary ===============================
  7. venv/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15
  8. /home/jihoon/Documents/A-Neural-Algorithm-of-Artistic-Style/venv/lib/python3.6/site-packages/tensorflow_core/python/pywrap_tensorflow_internal.py:15: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  9. import imp
  10. -- Docs: https://docs.pytest.org/en/latest/warnings.html
  11. ==================== 3 passed, 1 warnings in 24.53 seconds =====================

BibTeX

  1. @article{DBLP:journals/corr/GatysEB15a,
  2. author = {Leon A. Gatys and
  3. Alexander S. Ecker and
  4. Matthias Bethge},
  5. title = {A Neural Algorithm of Artistic Style},
  6. journal = {CoRR},
  7. volume = {abs/1508.06576},
  8. year = {2015},
  9. url = {http://arxiv.org/abs/1508.06576},
  10. archivePrefix = {arXiv},
  11. eprint = {1508.06576},
  12. timestamp = {Mon, 13 Aug 2018 16:48:03 +0200},
  13. biburl = {https://dblp.org/rec/bib/journals/corr/GatysEB15a},
  14. bibsource = {dblp computer science bibliography, https://dblp.org}
  15. }

Author

Jihoon Kim (@jihoonerd)