/neural-style-transfer

Multiple Style Transfer Network Using Conditional Instance Normalization in PyTorch

Primary LanguageJupyter Notebook

Neural Style Transfer

This is a simple implementation Multiple Style Transfer Network mentioned in paper A Learned Representation For Artistic Style. The network is trained on COCO Dataset containing 80K images for 40K iteration. However we can use any dataset to while testing the style-transfer model. The model is trained using 6 style images taken from WikiArt Dataset provided by ArtGAN repo.

Here's a blog I wrote that describes the mathematics for neural style transfer in detail.

Requirement

  • PyTorch
  • torchvision
  • OpenCV (cv2)
  • Numpy
  • PIL

Conditional Instance Normalization

PyTorch does not contain api for Conditional Instance Normalization. This is a implementation that uses code from torch BatchNorm and is tweaked as to have condition learnable weights.

The idea is to have weight tensor of size L x C, where L is the no. of style representations during training.

During the forward pass we provide input image as well as style condition "label" ~ [0,L). During backward pass only weigth[label:] tensor are updated and rest remaing the same. Here weight and bias refer to \gamma and \beta used for normalization.

Results

Test images from COCO dataset.

The model also runs good on CelebA dataset which was not used for training.

The model is fast enough to convert video into Artistic Styles in real-time.

References