Improving the Latent Space of Image Style Transfer

Yunpeng Bai, Cairong Wang, Chun Yuan, Yanbo Fan, Jue Wang

TL;DR

Standard neural style transfer methods rely on fixed, pre-trained VGG encoders whose latent spaces often contradict human visual perception and drop critical content details. This paper introduces two novel contrastive learning schemes to fine-tune the encoder, making its latent space more style-consistent and detail-preserving. This lightweight training modification seamlessly integrates into existing encoder-decoder frameworks (like AdaIN and SANet), significantly boosting stylization quality and preventing content distortion.

What Problem Does This Paper Address?

Since the pioneering work of Gatys et al., Neural Style Transfer (NST) has typically relied on a fixed, pre-trained Deep Convolutional Neural Network (usually VGG-19) to extract content and style features. Style is traditionally defined via feature statistics, such as the Gram matrix or channel-wise mean and variance.

However, the authors point out a fundamental flaw: the latent space of a standard pre-trained VGG network does not align with human subjective perception of style.

As shown in the paper, if you take a style image and spatially rearrange its pixels into blocks, a human still perceives it as the same style. Yet, a pre-trained VGG often calculates a larger style distance between the original image and its scrambled counterpart than it does between two completely different artistic styles.

Figure 1: The two images on the left are randomly selected from the style dataset. We rearrange one of them spatially to get the third image. Then, We use a pre-trained encoder used in previous methods to calculate the style distance for three images. Surprisingly, we find that the distance between the two images on the left was smaller than that of the two images with exactly the same style on the right, which indicates that the objective of the existing methods may not be consistent with the visual style.

When the optimization objective operates in such an distorted latent space, the network optimizes in the wrong direction. This mismatch leads to two major issues:

  1. Style Inconsistency: The generated images retain incorrect colors or fail to capture the true texture of the artwork.
  2. Content Leak/Loss: The encoder discards fine-grained structural details, causing parts of the content image to become unrecognizable or severely distorted.

Methods

Instead of keeping the encoder frozen, the authors propose fine-tuning it alongside the rest of the style transfer network using two contrastive learning mechanisms. To prevent the encoder's features from drifting too far from a stable baseline, they employ the original pre-trained VGG as a feature regularizer.

The core framework introduces two new loss functions:

1. Style Contrastive Loss ($L_{s-c}$)

To force the latent space to be style-consistent, the network must learn to group similar styles together and push different ones apart.

  • Positive Examples: The authors split a style image into $n \times n$ blocks and randomly shuffle them. This decouples the style from the macro-content layout while preserving the artistic texture.
  • Negative Examples: Content images within the training batch serve as negative examples. The loss pulls the stylized output closer to the shuffled style images and pushes it away from the content images in the embedding space.

2. Identity Preserve Content Contrastive Loss ($L_{c-c}$)

To combat content leak, the authors introduce a local-wise contrastive loss.

  • The network is tasked with reconstructing a content image by stylizing it with itself.
  • It randomly samples local blocks from the original content image and the reconstructed image.
  • The loss ensures that blocks from the same spatial position are pulled together in the embedding space, while blocks from different positions are pushed apart. This forces the encoder to retain sharp, local structural details.
Figure 3: Our identity preserve content contrastive loss. Ic (Is) is the input content (style) image and Icc(Iss) is the output image synthesized from this image pair (content or style). We sample some blocks of the restored and original images and compare them in a latent space. The features of the same position are pulled together, and different positions are pushed away. In this way, the encoder can retain more available details when extracting features.

Datasets

The authors validated their approach using standard benchmarks in the style transfer literature:

  • Content Images: MS-COCO (~80,000 training images)
  • Style Images: WikiArt (~80,000 training images)

Key Insights and Ideas

  • The VGG Paradox: A network trained for image classification isn't inherently optimized for style representation. Its distance metrics can be highly counter-intuitive to human vision, meaning "closer" in VGG space doesn't mean "more visually similar."
  • Shuffling as Style Preservation: Spatial shuffling is a remarkably simple yet effective data augmentation technique to isolate pure texture and color style from semantic content.
  • Encoder-Side Fix for Content Leak: While prior works tried to fix content distortion by modifying the decoder, this paper proves that the root cause often lies in the encoder discarding details too early. Fine-tuning the encoder with local contrastive constraints preserves those vital edges.

Key Results

The proposed training scheme was integrated into two state-of-the-art style transfer methods: AdaIN and SANet.

Qualitative Improvements

When applied to AdaIN, the refined encoder eliminated uncharacteristic colors and preserved sharp structural boundaries (such as the distinct lines of a human hand or face) that the baseline completely washed out.

Figure 4: Experiment on AdaIN

Quantitative User Study

Because style transfer is highly subjective, the authors conducted a user study with 50 participants evaluating 100 generated images. The preference scores showed a massive leap in quality across both baseline architectures:

Stylization Scheme Preference Score (Higher is Better)
AdaIN (Baseline) 0.153
Our AdaIN 0.228
SANet (Baseline) 0.242
Our SANet 0.377

Limitations and Future Work

  • Architecture Constraints: This method requires an encoder-decoder architecture to map the stylized results back to image space for the contrastive losses. Consequently, it cannot be applied to optimization-based style transfer methods (like the original Gatys et al. pixel-optimization approach).
  • Training Efficiency: Generating and loading multiple shuffled style positive examples during training adds computational overhead and reduces training throughput.
  • Future Direction: The authors plan to explore a universal pre-training scheme to create a standalone, style-optimized encoder that can be used out-of-the-box for various style transfer tasks without needing per-method fine-tuning.

Summary updated

BibTeX
@misc{bai2022improving,
  author = {Yunpeng Bai and Cairong Wang and Chun Yuan and Yanbo Fan and Jue Wang},
  title = {{Improving the Latent Space of Image Style Transfer}},
  year = {2022},
  eprint = {2205.12135},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.12135},
}
Figure