Neural style transfer implementation in TensorFlow with a couple improvements and quirks. Based on A Neural Algorithm of Artistic Style and improvements in Improving the Neural Algorithm of Artistic Style.
- Geometric weighting scheme for content and style layers.
- Utilizes all 16 convolutional layers in the VGG-19 model.
- Calculates Gram matrices using shifted activations.
- Feature comparisons with blurred chain correlations between local layers.
- Weighs feature comparisons within the same layer, l, and l and l - 1 differently. The first l and l correlation gets additional weight equal to the weight given to l and l - 1 comparisons.
- Blurs l and l - 1 correlation using a gaussian blur instead of a box blur.
- Hyperparameters...
Download some images to work with and the pretrained VGG-19 model (save the model file in the project's root directory, don't change it's name). Install NumPy, SciPy, and TensorFlow. If possible, install the version of TensorFlow that runs on your GPU, this speeds things up considerably. Then run the following in your terminal:
$python3 neural-style-transfer.py [content path] [style path] [output image width] [iterations]
Generated images are saved inside the "output" directory when the process is completed. Inside the "iterations" folder there will be generated images from every 100 iterations processed. Inside the "setup" folder will be the resized content and style images used during processing.
Content | Style | Output |
---|---|---|
![]() |
![]() |
![]() |
Content: Man in a Forest Landscape (Constant Alexandre Famin, ca. 1870)
Style: Cypresses (Vincent van Gogh, 1889)
Iterations: 5000
Content | Style | Output |
---|---|---|
![]() |
![]() |
![]() |
Content: 11:00 A.M. Monday, May 9th, 1910. Newsies at Skeeter's Branch, Jefferson near Franklin. They were all smoking. Location: St. Louis, Missouri. (Lewis Hine, May 9, 1910)
Style: Fleur de Lis (Robert Reid, ca. 1895-1900)
Iterations: 5000
Content | Style | Output |
---|---|---|
![]() |
![]() |
![]() |
Content: Medinet Habu (John Beasley Greene, 1854)
Style: Rochishin Chopping Off the Head of Nio (School of Katsushika Hokusai, 18th-19th century)
Iterations: 5000
Content | Style | Output |
---|---|---|
![]() |
![]() |
![]() |
Content: Sentinel Rock, Yosemite (attributed to Carleton E. Watkins, ca. 1872, printed ca. 1876)
Style: The Beeches (Asher Brown Durand, 1845)
Iterations: 5000