Transforming Art with AI

Neural Style Transfer

How it works
Neural Style Transfer (NST) is a complex process that combines stylistic components of images, requiring algorithms to maintain their integrity. The computational complexity of NST approaches is a major obstacle to realtime applications and interactive editing. Optimizing the process without sacrificing quality is crucial. NST models must also be able to generalize and adapt to various styles and materials, allowing users to regulate stylistic influence.
01
Feature Representation and Optimization

Neural Style Transfer is a deep neural network technique that extracts feature representations from images, optimizes them to minimize content and style loss, and uses techniques like gradient descent to adjust the image iteratively.

02
Content and Style Separation

Neural style transfer involves separating high-level structure and objects from textures, patterns, and artistic elements. This process involves extracting features at different layers of a neural network, enabling the recombination of content from one image with style from another.

03
Artistic Image Generation and Applications

Neural Style Transfer is a technique that applies renowned artworks or visual elements to existing images, enhancing visual content and enhancing photo and video editing, as well as studying neural network perception.

Our Implementation
The following explains the Style Transfer procedure using the VGG19 CNN

A pre-trained VGG19 CNN is divided into 6 slices and the output feature maps from each slice is taken as the network output. The content image is passed through this custom VGG19 and the 5th feature map is taken as the content target. Then, the style image is also passed through this custom VGG19 and the Gram matrices for each set of feature maps is calculated and treated as the taret gram matrices.

Passing through VGG19
Content and Style Extraction

Once the target content feature maps and target style gram matrices have been calculated, we initialize an optimizing image (either same as the content image, or random noise) which will be optimized to acquire the target content and style.

At every step, this optimizing image is passed through the custom CNN and the difference between its content feature map & style gram matrices and the target content & style is calculated as a weighted loss.

Optimization process

Once the loss is calculated, we backpropagate it through the network to the image pixel values themselves. Then, we change the values of the pixels in the image itself in order to minimize the loss that we have calculated.

This optimization process can be carried out through some standard optimization techniques like Adam or LBFGS. At each iteration of the optimization procedure, we change the values of the pixels in the optimizing image and the proces is repeated for a certain number of epochs or until we reach a certain optimal value for the loss function.

Examples
Gallery of images demonstrating the results of the style transfer
picasso_weeping_woman
STYLE

Image of Picasso Weeping Woman From which Style is Extracted

Sample of tubingen image
CONTENT

Content Image Tubingen

tubingen styled as vg_starry_night
OUTPUT

Content Image of Tubingen Styled as Van Gogh Starry Nights

vg_starry_night
STYLE

Image of Van Gogh Starry Night From which Style is Extracted

tubingen styled as mosaic
OUTPUT

Content Image of Tubingen Styled as Mosaic

mona_lisa styled as ben_giles
OUTPUT

Content Image of Mona Lisa Styled as BEn Giles Collages

tubingen styled as wave_crop
OUTPUT

Content Image of Tubingen Styled as Wave Crop

wave_crop
STYLE

Image of Wave Crop from which Style is Extracted

candy
STYLE

A Image of Candy Pattern from which Style is Extracted

ben_giles
STYLE

A Image of Ben Giles Collages from which Style is Extracted

tubingen styled as picasso_weeping_woman
OUTPUT

Content Image of Tubingen Styled as Picasso Weeping Woman

mona_lisa styled as wave_crop
OUTPUT

Content Image of Mona Lisa Styled as Wave Crop

mosaic
STYLE

A Image of Mosaic Pattern From which Style is Extracted

tubingen styled as candy
OUTPUT

Content Image of Tubingen Styled as Candy

mona_lisa styled as mosaic
OUTPUT

Content Image of Mona Lisa Styled as Mosaic

tubingen styled as ben_giles
OUTPUT

Content Image of Tubingen Styled as Ben Giles Collages

lion_image
CONTENT

Content Image of a Lion

mona_lisa
CONTENT

Content Image of Mona Lisa

lion styled as mosaic
OUTPUT

Content Image of Lion Styled as Mosaic

mona_lisa styled as vg_starry_night
OUTPUT

Content Image of Mona Lisa Styled as Van Gogh Starry Night

mona_lisa styled as picasso_weeping_woman
OUTPUT

Content Image of Mona Lisa Styled as Picasso Weeping Woman

Check the Code
You can follow the below links to examine the code repository at github
Git repo
Neural-Style-Transfer

You can find the code and documentation here.

Check the repo
The style transfer is mainly implemented in the following three files
vgg_nets.py
vgg_nets.py

This module defines VGG16 and VGG19 neural network architectures. These networks are used for feature extraction from images, specifically for capturing content and style information.

Go to the code
utils.py
utils.py

This module contains functions to load and preprocess images. It converts image data to tensors, applies normalization, and prepares them for input to the neural network.

Go to the code
image_style_transfer.py
image_style_transfer.py

This file is responsible for the core of the style transfer process. It initializes the optimizing image and performs style transfer optimization on the image, using the configuration specified by the user.

Go to the code
References

[I]

Gatys, L. A., Ecker, A., & Bethge, M. (2015). A neural algorithm of artistic style. arXiv (Cornell University). https://arxiv.org/abs/1508.06576

[II]

Li, Y., Wang, N., Liu, J., & Hou, X. (2017). Demystifying neural style transfer. arXiv (Cornell University). https://arxiv.org/abs/1701.01036

[III]

Johnson, J., Alahi, A., & Li, F. (2016). Perceptual losses for Real-Time style transfer and Super-Resolution. In Lecture Notes in Computer Science (pp. 694-711). https://arxiv.org/abs/1603.08155

[IV]

Krizhevsky, A., Sutskever, I., & Hinton, G. E. (2012). ImageNet Classification with Deep Convolutional Neural Networks. Neural Information Processing Systems, 25, 1097–1105. https://doi.org/10.1145/3065386

[V]

Simonyan, K., & Zisserman, A. (2014). Very deep convolutional networks for Large-Scale image recognition. Computer Vision and Pattern Recognition. https://arxiv.org/abs/1409.1556

[VI]

Jing, Y., Yang, Y., Feng, Z., Ye, J., Yu, Y., & Song, M. (2020). Neural Style Transfer: a review. IEEE Transactions on Visualization and Computer Graphics, 26(11), 3365-3385. https://doi.org/10.1109/TVCG.2019.2921336

[VII]

Image Stylization: History and Future (Part 1). (n.d.). Adobe Research. https://research.adobe.com/news/image-stylization-history-and-future/

[VIII]

Style Transfer Guide - Fritz ai. (2023, July 14). Fritz Ai. https://fritz.ai/style-transfer/

Contact Us
Phone

Alex Prateek Shankar : +91-96545-72100

Sneh Shah : +91-94289-11398

Address

Bengaluru, Karnataka,

India

Email

Alex Prateek Shankar : alex94prateek@gmail.com

Sneh Shah : snehshah2901@gmail.com