pastiche A literary, artistic, musical, or architectural work that imitates the style of previous work.
―Merriam-Webster dictionary
Update 1/20/2021: The command line usage snippets were updated in accordance with v1.1.0
.
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 CONTENT \
--styles STYLE [STYLE ..] \
--output OUTPUT
CONTENT
is the path to the content image, STYLE
is a path to a 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
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.