Zero-Shot Contrastive Loss for Text-Guided Diffusion Image Style Transfer

Serin Yang, Hyunmin Hwang, Jong Chul YeICCV 2023

Abstract

Diffusion models have shown great promise in text-guided image style transfer, but there is a trade-off between style transformation and content preservation due to their stochastic nature. Existing methods require computationally expensive fine-tuning of diffusion models or additional neural networks. To address this, here we propose a zero-shot contrastive loss for diffusion models that doesn’t require additional fine-tuning or auxiliary networks. By leveraging patch-wise contrastive loss between generated samples and original image embeddings in the pre-trained diffusion model, our method can generate images with the same semantic content as the source image in a zero-shot manner. Our approach outperforms existing methods while preserving content and requiring no additional training, not only for image style transfer but also for image-to-image translation and manipulation. Our experimental results validate the effectiveness of our proposed method.

Introduction

Diffusion models have revolutionized the field of image generation, yet applying them to style transfer remains a significant challenge. Style transfer requires a delicate balance: modifying the aesthetic "look" of an image (e.g., converting a photograph into a "Cubism" painting) while strictly preserving the underlying "content" (the spatial arrangement of objects and features).

The primary obstacle is the stochastic nature of the diffusion process. Because these models operate by iteratively removing noise, the structural integrity of the source image is often lost. Current state-of-the-art solutions typically rely on either computationally intensive fine-tuning for every new style or the integration of auxiliary networks to monitor content preservation. This research introduces ZeCon (Zero-shot Contrastive loss), a training-free framework that enforces content consistency using the internal representations of a standard, pre-trained diffusion model.

Methodology

ZeCon: Zero-Shot Contrastive Loss

Inspired by Contrastive Unpaired Translation (CUT), the proposed ZeCon loss treats image patches as "anchors." It ensures that a specific patch in the generated image remains more similar to its corresponding patch in the source image (a positive pair) than to other random patches (negative pairs). A key innovation is extracting these features directly from the U-Net encoder of the diffusion model. This demonstrates that the model’s internal layers already possess a sophisticated understanding of spatial structure, eliminating the need for external feature extractors like VGG or ResNet.

The ZeCon architecture integrates CLIP-based style guidance with a patch-wise contrastive loss extracted directly from the diffusion model's U-Net.

Guidance and Sampling Strategy

To achieve high-fidelity results, the framework combines ZeCon with standard VGG feature loss and MSE pixel loss for "Total Content Guidance." Style is steered via a CLIP model using both global and directional losses to ensure cohesive transformation without artifacts. The sampling process utilizes a hybrid approach: DDIM for the forward (noising) process to preserve latent information, and DDPM for the reverse (denoising) process to allow for expressive style modulation.

Experimental Results

Qualitative and Quantitative Performance

ZeCon was evaluated across diverse domains, including human faces (FFHQ, CelebA-HQ), general scenes (LSUN Church), and artistic styles (Wikiart). In comparative studies, ZeCon consistently outperformed established methods like StyleCLIP, VQGAN-CLIP, and DiffusionCLIP.

Qualitative comparison of ZeCon against state-of-the-art methods across various style prompts, demonstrating superior content preservation and style fidelity.

User studies confirmed these findings, with ZeCon achieving a score of 4.61/5.0 for content preservation and 4.23/5.0 for style transformation. Visually, the method maintains intricate details—such as the specific geometry of a hat or the positioning of hands—that competing models often distort or omit.

Efficiency and Versatility

By avoiding the fine-tuning stage, ZeCon offers significant speed advantages. While methods like DiffusionCLIP require approximately 400 seconds per transfer, ZeCon completes the process in roughly 38 seconds. Furthermore, the method demonstrates "cross-domain mastery," successfully translating images between disparate domains (e.g., turning a classical portrait into a realistic photo) and performing complex image manipulations, such as altering an animal's facial expression.

Conclusion

ZeCon provides a robust, zero-shot solution for text-guided style transfer by leveraging the latent spatial knowledge within pre-trained diffusion models. By replacing expensive training with a patch-wise contrastive loss, it achieves a superior balance of style and content preservation. Future work will focus on automating hyperparameter selection to further enhance user accessibility.

Summary updated

BibTeX
@inproceedings{yang2023zero,
  author = {Serin Yang and Hyunmin Hwang and Jong Chul Ye},
  title = {{Zero-Shot Contrastive Loss for Text-Guided Diffusion Image Style Transfer}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
  url = {https://openreview.net/forum?id=p9uG25ZOtp},
}
Figure