🎨 pastiche

pastiche A literary, artistic, musical, or architectural work that imitates the style of previous work.

―Merriam-Webster dictionary

I recently implemented pastiche, a PyTorch-based Python program for applying neural style transfer [1]. Given a content image C and a style image S, neural style transfer (NST) synthesizes a new image I that retains the content from C and style from S. This is achieved by iteratively updating I so that relevant properties of its representation within the VGG neural network [3] approach the corresponding properties for C and S.

The library is available on PyPI and can be installed with pip.

$ pip3 install pastiche

The example image above was synthesized by applying the style from Vincent van Gogh’s The Starry Night to a photo I took in Boston in 2015.

The command line usage is shown below. Use --help to access documentation for the additional options (e.g., --device for controlling whether to use a CPU or GPU).

$ 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

The source code is available on GitHub:
https://github.com/dstein64/pastiche

The README includes an example showing how to generate a high-resolution image incrementally, with increasing resolution, using the coarse-to-fine approach described in [2].

The --preserve-color option can be used to retain colors from the content image.

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.

[3] Simonyan, Karen, and Andrew Zisserman. “Very Deep Convolutional Networks for Large-Scale Image Recognition.” ArXiv:1409.1556 [Cs], September 4, 2014. http://arxiv.org/abs/1409.1556.

This entry was tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *