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

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 STYLE 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 STYLE OUTPUT

There are various options, including but not limited to:

  • Device (CPU versus GPU)
  • 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]. The commands are shown below. Depending on GPU memory availability, the commands may necessitate execution on a CPU (--device cpu).

$ pastiche \
    --num-steps 2000 \
    boston.jpg \
    vangogh_starry_night.jpg \
    pastiche0.png

$ pastiche \
    --size 1024 \
    --num-steps 1000 \
    --init pastiche0.png \
    boston.jpg \
    vangogh_starry_night.jpg \
    pastiche1.png

$ pastiche \
    --size 2048 \
    --num-steps 500 \
    --init pastiche1.png \
    boston.jpg \
    vangogh_starry_night.jpg \
    pastiche2.png

$ pastiche \
    --size 4096 \
    --num-steps 100 \
    --init pastiche2.png \
    boston.jpg \
    vangogh_starry_night.jpg \
    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.0.1.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.0.1-py3-none-any.whl (18.5 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pastiche-1.0.1.tar.gz
  • Upload date:
  • Size: 18.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.2

File hashes

Hashes for pastiche-1.0.1.tar.gz
Algorithm Hash digest
SHA256 fb68dfa7478bd23c9df6cdc6738ddd047a1c267bb939124d45bae8bc838cea29
MD5 a5376fc4b27bca3ae20367916f3acbe7
BLAKE2b-256 b2e1c2a855952ea0331840f82b532cfdb34a75b527040c1a34fd36199f65c668

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pastiche-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.2

File hashes

Hashes for pastiche-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6490cf5ec0c10a4bc5c69bb3250bf0d930d3f65fb210020ab2e84a7a8bee379
MD5 db04f62d6f05501a32f414434a8a97ef
BLAKE2b-256 e474e6510a56efa519074a5b8cfa619ba79a8dbf6b1c0c2bbfc31d623442597d

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