Skip to content
Branch: master
Find file History

Fast Neural Style Transfer


This artistic style transfer model mixes the content of an image with the style of another image. Examples of the styles can be seen here.


The model uses the method described in Perceptual Losses for Real-Time Style Transfer and Super-Resolution along with Instance Normalization.


Model Download MD5 Checksum Download (with sample test data) ONNX version Opset version
Mosaic 6.6 MB 39f0d4d12cf758a7aa31eb150d66244a 7.2 MB 1.4 9
Candy 6.6 MB ef6b9b26d2821ee0c082f229b2e6efcd 7.2 MB 1.4 9
Rain Princess 6.6 MB 8253cf9670bb24b38152bd71de5571f1 7.2 MB 1.4 9
Udnie 6.6 MB f3797cf0dd731c83b307ffa76aed2e67 7.2 MB 1.4 9
Pointilism 6.6 MB e3241660ecd9f14a671d7229bf18cbd1 7.2 MB 1.4 9
Mosaic 6.6 MB a92570e1f6ce63b55daab1d4ba979696 7.2 MB 1.4 8
Candy 6.6 MB f1de4e7d66a4b286f87ace03ea4d539e 7.2 MB 1.4 8
Rain Princess 6.6 MB 77947dd0402f2076b3386078ed97ae3e 7.2 MB 1.4 8
Udnie 6.6 MB c38e1c3cfc0d07615ea6ba8d6e73ef61 7.2 MB 1.4 8
Pointilism 6.6 MB a188752e35eaf7c77381601151c63bb4 7.2 MB 1.4 8


Refer to style-transfer-ort.ipynb for detailed preprocessing and postprocessing.

Input to model

The input to the model are 3-channel RGB images. The images have to be loaded in a range of [0, 255]. If running into memory issues, try resizing the image by increasing the scale number.

Preprocessing steps

from PIL import Image
import numpy as np

# loading input and resize if needed
image ="PATH TO IMAGE")
size_reduction_factor = 1 
image = image.resize((int(image.size[0] / size_reduction_factor), int(image.size[1] / size_reduction_factor)), Image.ANTIALIAS)

# Preprocess image
x = np.array(image).astype('float32')
x = np.transpose(x, [2, 0, 1])
x = np.expand_dims(x, axis=0)

Output of model

The converted ONNX model outputs a NumPy float32 array of shape [1, 3, ‘height’, ‘width’]. The height and width of the output image are the same as the height and width of the input image.

Postprocessing steps

result = np.clip(result, 0, 255)
result = result.transpose(1,2,0).astype("uint8")
img = Image.fromarray(result)

Dataset (Train and validation)

The original fast neural style model is from pytorch/examples/fast_neural_style. All models are trained using the COCO 2014 Training images dataset [80K/13GB].


Refer to pytorch/examples/fast_neural_style for training details in PyTorch. Refer to conversion.ipynb to learn how the PyTorch models are converted to ONNX format.


Original style transfer model in PyTorch:


Jennifer Wang



You can’t perform that action at this time.