# Perceptual Losses for Real-Time Style Transfer and Super-Resolution

Perceptual losses enable real-time style transfer

Justin Johnson, Alexandre Alahi, Li Fei-Fei · arXiv · 2016-3-27

- **Problem** Per-pixel losses miss perceptual differences between images, while optimization-based perceptual methods take hundreds of iterations per image. Real-time use was therefore out of reach.
- **Method** The authors train a feed-forward network with perceptual losses computed by a frozen VGG-16. Instead of a per-pixel error, the network learns to match high-level features in a single pass.
- **Results** The style transfer network took 0.015s per 256×256 image, compared to 15.86s for 500 iterations of the baseline. Its outputs look similar to the baseline's.

## Why per-pixel losses and slow optimization both fall short

Super-resolution, colorization and segmentation all map an input image to an output image, and a common recipe trains a feed-forward network with a per-pixel loss. Such a network is cheap at test time, because producing an output takes one pass through it. The weak point is the loss itself: two images that look alike to a person can score far apart when compared pixel by pixel.

This matters most for super-resolution, where fine detail has to be inferred from a visually ambiguous low-resolution input.

Perceptual losses, built on feature differences from a pretrained classifier, avoid this pixel-by-pixel mismatch. So far they have mainly served to generate images by optimization, and inference then means solving an optimization problem for each image. Gatys et al's style transfer is the clearest case: its quality is high, but each stylized image typically needs around 500 iterations, and every iteration passes forward and backward through the loss network.

The question the authors ask is whether a network can learn that optimization once and then answer in a single pass.

## Training one network against fixed perceptual losses

The key idea is to keep the feed-forward network and change only its training signal. Instead of a per-pixel error, the network is trained with losses that compare high-level features from a classifier that stays frozen. Because that classifier already encodes perceptual and semantic information, the transformation network inherits this knowledge rather than learning it from scratch.

The system has two parts: an image transformation network \\(f\_W\\) with weights \\(W\\), and a loss network \\(\\phi\\). The transformation network maps an input \\(x\\) to an output \\(\\hat{y} = f\_W(x)\\), and several loss functions \\(\\ell\_i\\) compare \\(\\hat{y}\\) with targets \\(y\_i\\). Training uses stochastic gradient descent on a weighted sum of these losses, written as \\\[ W^\* = \\arg\\min\_W \\mathbb{E}\_{x,\\{y\_i\\}}\\Big\[\\sum\_i \\lambda\_i \\ell\_i(f\_W(x), y\_i)\\Big\] \\\] where the weights \\(\\lambda\_i\\) set the mix of the terms.

Only \\(W\\) is updated, and the loss network stays fixed throughout training.

For style transfer the content target is the input image, and the authors train one network per style target. So the style is fixed in each trained network's weights, and the network doesn't take a new style at run time. For super-resolution the content target is the ground-truth high-resolution image, the style loss isn't used, and there is one network per upsampling factor.

The network body uses five residual blocks, and it has no pooling layers. Downsampling and upsampling both use strided convolutions, and non-residual layers are followed by spatial batch normalization and ReLU, except the output layer. The output layer uses a scaled tanh, which keeps output pixels in the range \[0, 255\]. Because the network is fully convolutional, the trained model can be applied to images of any resolution at test time.

For style transfer, two stride-2 convolutions downsample the input before the residual blocks, and two stride-1/2 layers upsample it afterwards. The second argument concerns receptive fields: after downsampling by D, each extra 3×3 layer grows the effective receptive field by 2D instead of 2. Residual connections make the identity mapping easy to learn, which suits transformations whose output should share structure with the input.

Super-resolution differs in its upsampling: rather than enlarging the input with bicubic interpolation first, the network ends with log2 f stride-1/2 convolutions learned jointly with the rest. The input is a low-resolution patch of size 3 × 288/f × 288/f, and the output is a high-resolution patch of size 3 × 288 × 288.

## Feature, style and pixel losses

The loss network is a 16-layer VGG network pretrained on ImageNet, used in every experiment. Let \\(\\phi\_j(x)\\) be the activations at layer \\(j\\), a feature map of shape \\(C\_j \\times H\_j \\times W\_j\\). The feature reconstruction loss is the squared Euclidean distance between these activations for output and target, normalized by \\(C\_j H\_j W\_j\\): \\\[ \\ell^{\\text{feat}}\_{\\phi,j}(\\hat{y},y) = \\frac{1}{C\_j H\_j W\_j}\\,\\lVert \\phi\_j(\\hat{y}) - \\phi\_j(y)\\rVert\_2^2 \\\] Matching early layers gives images close to the target pixel by pixel, while matching higher layers keeps content and spatial layout but lets color, texture and exact shape drift.

The style loss starts from the Gram matrix of a layer, whose entries are \\(G^{\\phi}\_j(x)\_{c,c'} = \\frac{1}{C\_j H\_j W\_j}\\sum\_{h}\\sum\_{w}\\phi\_j(x)\_{h,w,c}\\,\\phi\_j(x)\_{h,w,c'}\\). Each entry measures how strongly two channels activate together across the spatial grid, which captures style without spatial layout. The style loss is the squared Frobenius norm of the difference between the Gram matrices of output and style target: \\\[ \\ell^{\\text{style}}\_{\\phi,j}(\\hat{y},y) = \\lVert G^{\\phi}\_j(\\hat{y}) - G^{\\phi}\_j(y)\\rVert\_F^2 \\\] Because the Gram matrices have the same shape whatever the image size, this loss stays defined when output and target differ in size, and a set of layers \\(J\\) is handled by summing the per-layer losses.

The pixel loss is the normalized squared distance \\(\\ell\_{\\text{pixel}}(\\hat{y},y) = \\lVert \\hat{y}-y\\rVert\_2^2 / CHW\\), and it can only be used when a ground-truth target exists. A total variation regularizer \\(\\ell\_{TV}(\\hat{y})\\) is added to encourage spatial smoothness in the output. Style transfer uses the feature loss at relu2\_2 and the style loss at relu1\_2, relu2\_2, relu3\_3 and relu4\_3, while super-resolution uses the feature loss at relu2\_2 only.

## Style transfer: matching the optimization baseline, much faster

The authors reimplemented the Gatys et al baseline, starting from white noise and optimizing with L-BFGS. Unconstrained optimization often leaves pixels outside \[0, 255\], so the baseline was run with projected L-BFGS that clips the image at every iteration, which matches the constraint on the network's output. Most baseline runs converged within 500 iterations.

The transformation networks were trained on 80k MS-COCO images resized to 256 × 256, with a batch size of 4 for 40,000 iterations and Adam at a learning rate of 1 × 10⁻³. The total variation strength was chosen per style between 1 × 10⁻⁶ and 1 × 10⁻⁴ by cross-validation, and training took roughly 4 hours on a single GTX Titan X GPU.

On 50 MS-COCO validation images with The Muse as the style image, the authors recorded the baseline's objective at each iteration and the network's objective per image. The network's objective is comparable to the value reached after 50 to 100 iterations of the baseline. The same comparison at 512×512 and 1024×1024 gives a similar picture, so the network keeps minimizing the objective on images larger than its 256×256 training size.

At 256×256 the network took 0.015s per image, compared to 15.86s for 500 iterations of the baseline, a speedup of 1060x. At 512×512 the network processes images at 20 FPS, which the authors take as enough for real-time style transfer or video. The gain comes from replacing hundreds of forward and backward passes through VGG-16 with one forward pass of the transformation network.

Qualitatively the outputs look similar to the baseline, with the same λ values used for both methods on the same content images from MS-COCO 2014 validation. The authors read the results as showing that the network keeps people and animals more than background, which they attribute to VGG-16 features selective for those objects.

## Super-resolution: finer edges with a lower PSNR and SSIM

The authors argue that ×4 and ×8 super-resolution need semantic reasoning, so they train with a feature reconstruction loss instead of the per-pixel loss usually used. PSNR is equivalent to the per-pixel loss, so a model trained with a per-pixel loss should win on PSNR, which is why the authors state their aim is qualitative.

The models were trained on 288×288 patches from 10k MS-COCO images, with low-resolution inputs made by Gaussian blur with σ = 1.0 and bicubic downsampling. Training ran for 200k iterations with a batch size of 4 and Adam at 1 × 10⁻³, followed by histogram matching against the low-resolution input. The pixel-loss models use the same data, architecture and training, so differences between the two losses are isolated.

The models were evaluated on Set5, Set14 and BSD100 with PSNR and SSIM computed on the Y channel after conversion to YCbCr. At ×4, the feature-loss model reconstructs sharp edges and fine details such as eyelashes better than the compared methods. A slight cross-hatch pattern visible under magnification lowers its PSNR and SSIM relative to the baseline methods.

Its background trees stay diffuse, which the authors take as a sign that the model is more aware of image semantics. The pixel-loss model produces fewer visual artifacts and higher PSNR, but the feature-loss model reconstructs fine details better, which the authors weigh as the more pleasing result.

## Limitations and untested settings

PSNR and SSIM rely only on low-level pixel differences and assume additive Gaussian noise, and both correlate poorly with human judgement of visual quality. The super-resolution comparison covers only ×4 and ×8, and SRCNN appears only at ×4. The objective comparison uses 50 MS-COCO validation images and a single style image, The Muse. Each style transfer network is trained for one style target, so a new style needs a new network.

Only VGG-16 was used as the loss network, and colorization and semantic segmentation were not tested. Whether loss networks trained on other tasks or datasets change the semantic knowledge transferred is left for future work.

## Paper info

- **Authors**: Justin Johnson, Alexandre Alahi, Li Fei-Fei
- **Venue**: arXiv · Preprint
- **First published**: 2016-3-27
- **Added**: 2026-11-11
- **Updated**: 2016-3-27
- **Version**: v1
- **arXiv**: 1603.08155
- **Category**: cs.CV · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1603.08155v1) · [PDF ↗](https://arxiv.org/pdf/1603.08155v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Justin Johnson, Alexandre Alahi, Li Fei-Fei (2016). Perceptual Losses for Real-Time Style Transfer and Super-Resolution. arXiv:1603.08155v1. https://arxiv.org/abs/1603.08155v1

**BibTeX**

```
@misc{johnson2016perceptual,
  title = {{Perceptual Losses for Real-Time Style Transfer and Super-Resolution}},
  author = {Justin Johnson and Alexandre Alahi and Li Fei-Fei},
  year = {2016},
  eprint = {1603.08155},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1603.08155v1}
}
```

## Other paper commentary

- [Learning Deep Features for Discriminative Localization](https://refivu.com/en/papers/6bdcd2a6-8c81-46b4-95d2-9560f97fd427-learning-deep-features-for-discriminative-localization.md)
- [V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation](https://refivu.com/en/papers/a6e119c3-3c19-41b0-afee-c1d81e538a35-v-net-fully-convolutional-neural-networks-for-volumetric.md)
- [Aggregated Residual Transformations for Deep Neural Networks](https://refivu.com/en/papers/e793fb66-bc1f-4ced-89ed-5f634b4590ea-aggregated-residual-transformations-for-deep-neural-networks.md)
- [YOLOv7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors](https://refivu.com/en/papers/c2cb4858-244f-407a-916b-4d41a9df7d4f-yolov7-trainable-bag-of-freebies-sets-new-state.md)
- [A Survey on Deep Learning in Medical Image Analysis](https://refivu.com/en/papers/4d173b56-9ea6-4644-98f2-af1794e63965-a-survey-on-deep-learning-in-medical-image.md)
- [The Unreasonable Effectiveness of Deep Features as a Perceptual Metric](https://refivu.com/en/papers/7a2a39ad-a72d-46f5-b96c-8392e55b66ee-the-unreasonable-effectiveness-of-deep-features-as-a.md)
- [node2vec: Scalable Feature Learning for Networks](https://refivu.com/en/papers/dc0725e4-ec21-4d60-9363-0eac2fc69a10-node2vec-scalable-feature-learning-for-networks.md)
- [Explainable Artificial Intelligence (XAI): Concepts, Taxonomies, Opportunities and Challenges toward Responsible AI](https://refivu.com/en/papers/3f686a20-03db-4642-80bb-f85fafc1d04f-explainable-artificial-intelligence-xai-concepts-taxonomies.md)
- [Stop Explaining Black Box Machine Learning Models for High Stakes Decisions and Use Interpretable Models Instead](https://refivu.com/en/papers/96d240ca-7c32-4f79-8167-c2beafc2a38f-stop-explaining-black-box-machine-learning-models-for.md)
- [Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network](https://refivu.com/en/papers/5a2dbd66-c794-464b-9d10-02f19eeb20e7-photo-realistic-single-image-super-resolution-using-a.md)
- [UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction](https://refivu.com/en/papers/44ccc549-6643-4369-889c-f60f3d61cbf4-umap-uniform-manifold-approximation-and-projection-for.md)

## Terms in this paper

- [ADAM](https://refivu.com/en/terms/0e9ad0199e08-adam)
- [PSNR](https://refivu.com/en/terms/fcbb9b8276a7-psnr)
- [SSIM](https://refivu.com/en/terms/a5c530b66e8d-ssim)
- [VGG-16](https://refivu.com/en/terms/50d02785f4b9-vgg-16)
- [Set14](https://refivu.com/en/terms/e149cff83a15-set14)
- [Set5](https://refivu.com/en/terms/10c3b328190e-set5)
- [SRCNN](https://refivu.com/en/terms/6a9cf6ae7c80-srcnn)
- [Perceptual loss](https://refivu.com/en/terms/8ced141e2959-perceptual-loss)
- [BSD100](https://refivu.com/en/terms/3e90ac61991d-bsd100)
- [Gram matrix](https://refivu.com/en/terms/0c7320647dff-gram-matrix)
- [residual blocks](https://refivu.com/en/terms/310231b03c2b-residual-blocks)
- [style transfer](https://refivu.com/en/terms/00f82d672737-style-transfer)
- [ImageNet dataset](https://refivu.com/en/terms/6d415a96eb58-imagenet-dataset)
- [Microsoft COCO dataset](https://refivu.com/en/terms/316d96f943a2-microsoft-coco-dataset)
- [fractionally-strided convolution](https://refivu.com/en/terms/f21ece086e18-fractionally-strided-convolution)
- [pixel loss](https://refivu.com/en/terms/1ff1ed3e6360-pixel-loss)
- [spatial batch normalization](https://refivu.com/en/terms/a56fa63cca43-spatial-batch-normalization)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/780825d2-51b4-4426-9340-0f1859a637a2-perceptual-losses-for-real-time-style-transfer-and)
