Skip to main content

A PyTorch implementation of Neural Style Transfer (NST)

Project description

Build Status

pastiche

A PyTorch-based Python implementation of Neural Style Transfer [1].


Features

  • Support for saving intermediate images during optimization
  • An option for preserving colors from the content image
  • Multiple-device computation (--supplemental-device)
  • Style transfers utilizing multiple style images

Installation

Requirements

  • Python 3.6 or greater

Install

$ pip3 install pastiche

Update

$ pip3 install --upgrade pastiche

Usage

The program is intended to be used from the command line.

The general command line usage is shown below.

$ pastiche --content CONTENT --styles STYLE [STYLE ...] --output OUTPUT

CONTENT is the path to the content image, STYLE is the path to the style image, and OUTPUT is the path to save the synthesized pastiche PNG file.

If the launcher script was not installed within a directory on your PATH, pastiche can be launched by passing its module name to Python.

$ python3 -m pastiche --content CONTENT --styles STYLE [STYLE ...] --output OUTPUT

There are various options, including but not limited to:

  • Devices (GPU, CPU, and/or a multi-device assortment)
  • Number of optimization iterations
  • VGG layers to utilize
  • Loss function term weights

For the full list of options and the corresponding documentation, see the source code or use --help.

$ pastiche --help

Example

The image above was generated by applying the style from Vincent van Gogh's The Starry Night to a photo I took in Boston in 2015. The high-resolution image was generated incrementally, with increasing resolution, using the coarse-to-fine approach described in [2]. Example commands are shown below. Depending on GPU memory availability, the commands may necessitate execution partially on a CPU (e.g., --device cuda:0 --supplemental-device cuda:1 10 --supplemental-device cpu 20 would configure GPU 0 for layers 0 through 9, GPU 1 for layers 10 through 19, and the CPU for layers 20 through 36).

$ pastiche                            \
    --device cuda                     \
    --num-steps 2000                  \
    --content boston.jpg              \
    --styles vangogh_starry_night.jpg \
    --output pastiche0.png

$ pastiche                            \
    --device cuda                     \
    --size 1024                       \
    --num-steps 1000                  \
    --init pastiche0.png              \
    --content boston.jpg              \
    --styles vangogh_starry_night.jpg \
    --output pastiche1.png

# Split the computation across a GPU (layers 0 through 5 and 10 through 19), another GPU (layers 6
# through 9), and a CPU (layers 20 through 36). This device strategy is for the purpose of
# illustration. Tuning would be required for an actual device setup.
$ pastiche                            \
    --device cuda:0                   \
    --supplemental-device cuda:1 6    \
    --supplemental-device cuda:0 10   \
    --supplemental-device cpu 20      \
    --info-step 10                    \
    --size 2048                       \
    --num-steps 500                   \
    --init pastiche1.png              \
    --content boston.jpg              \
    --styles vangogh_starry_night.jpg \
    --output pastiche2.png

# Split the computation across a GPU (layers 0 through 3) and CPU (layers 4 through 36). This
# device strategy is for the purpose of illustration. Tuning would be required for an actual
# device setup.
$ pastiche                            \
    --device cuda                     \
    --supplemental-device cpu 4       \
    --info-step 1                     \
    --size 4096                       \
    --num-steps 100                   \
    --init pastiche2.png              \
    --content boston.jpg              \
    --styles vangogh_starry_night.jpg \
    --output pastiche3.png

$ convert pastiche3.png pastiche.jpg  # requires ImageMagick

The --preserve-color option can be used to retain colors from the content image. The image below was generated using the same commands as above (up to --size 2048), with the addition of --preserve-color.

License

The source code has an MIT License.

See LICENSE.

References

[1] Gatys, Leon A., Alexander S. Ecker, and Matthias Bethge. "A Neural Algorithm of Artistic Style." ArXiv:1508.06576 [Cs, q-Bio], August 26, 2015. http://arxiv.org/abs/1508.06576.

[2] Gatys, Leon A., Alexander S. Ecker, Matthias Bethge, Aaron Hertzmann, and Eli Shechtman. "Controlling Perceptual Factors in Neural Style Transfer." ArXiv:1611.07865 [Cs], November 23, 2016. http://arxiv.org/abs/1611.07865.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pastiche-1.2.0.tar.gz (18.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pastiche-1.2.0-py3-none-any.whl (18.5 MB view details)

Uploaded Python 3

File details

Details for the file pastiche-1.2.0.tar.gz.

File metadata

  • Download URL: pastiche-1.2.0.tar.gz
  • Upload date:
  • Size: 18.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for pastiche-1.2.0.tar.gz
Algorithm Hash digest
SHA256 9f8b08d7c385604e92b6c5f5e7a32c769532b39c797deebc889ad4c4d1fba986
MD5 60483e851b30e2f58cc978428a35a5cf
BLAKE2b-256 da8413bae3dcf7a2d99ec727f7e9b890bbca07242e67bd19ce56ec9c46ae5ae0

See more details on using hashes here.

File details

Details for the file pastiche-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: pastiche-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

File hashes

Hashes for pastiche-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b582766f7ada89ca8c9fdc917602ce8861a0ae682ae14e46040173073bc6bba5
MD5 c7f580b7c034962a6fbfed98fa808b4d
BLAKE2b-256 b409a91cda4f2885e03f07320ccff45c5354b26d9ecd93aab5592ce3062eb47b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page