Contrastive Learning Guided Latent Diffusion Model for Image-to-Image Translation

Qi Si, Bo Wang, Zhao ZhangarXiv 2025 · DOI

Abstract

Text-guided image-to-image (I2I) translation using Latent Diffusion Models (LDMs) often suffers from content drift and the need for meticulous prompt engineering. We present pix2pix-zeroCon, a training-free, zero-shot framework that addresses these issues. By leveraging an automated editing direction strategy and a novel patch-wise contrastive loss (CUT loss) extracted from the diffusion model’s internal U-Net features, pix2pix-zeroCon ensures high-fidelity structure preservation. Experimental results demonstrate that our method significantly outperforms existing zero-shot techniques in maintaining original image context while accurately reflecting target text modifications.

Introduction

Text-guided image-to-image translation—such as changing a "cat" to a "dog" or modifying a person's attire—is a core capability of modern generative models. However, two major hurdles persist in current workflows. First, Prompt Engineering remains difficult; users often struggle to craft the exact prompt required to describe a source image accurately enough for a clean edit. Second, Content Drift frequently occurs, where the model inadvertently alters non-edited regions of the image, such as the background or the subject's pose, during the denoising process.

While previous methods like pix2pix-zero utilized cross-attention maps to maintain layout, they often failed to capture fine-grained textures and structural nuances, leading to artifacts like "ghosting." pix2pix-zeroCon addresses these limitations by introducing a contrastive learning mechanism that operates directly on the model's internal features.

Methodology

The pix2pix-zeroCon framework operates on a pre-trained Stable Diffusion model without requiring any additional training or per-image fine-tuning. Its architecture is defined by three main pillars:

Automated Editing Direction

To eliminate the need for manual prompt crafting, the system uses BLIP to automatically caption the source image. GPT-3 then generates a diverse set of sentences for both the source and target concepts. By averaging the CLIP embeddings of these variations, the model calculates a robust "edit vector" ($\Delta c$) in the text embedding space, making the translation more stable and less prone to artifacts.

Cross-Attention Guiding Loss ($L_c$)

This loss ensures that the rough spatial layout remains consistent. By aligning the attention maps of the edited image with those of the original source, the model keeps objects in their original positions.

Patch-wise Contrastive Loss (CUT Loss - $L_e$)

This is the core innovation of the paper. Inspired by Contrastive Unpaired Translation, the authors maximize the mutual information between corresponding patches of the source and edited images. Crucially, they do not train a new encoder; instead, they extract spatial features directly from the diffusion model's own U-Net noise predictor. These internal layers already contain rich structural information, allowing the model to ensure that a patch of "dog fur" in the output corresponds exactly to the position and texture-logic of "cat fur" in the input.

A small gray kitten edited to be yawning, demonstrating the model's ability to handle structural nuances without losing identity.

Experimental Results

The model was evaluated on diverse benchmarks, including ImageNet-R, LAION-5B, and CelebAMask-HQ-512. pix2pix-zeroCon was compared against several state-of-the-art methods, including pnp, p2p-zero, DDS, and CDS.

Quantitative Performance

In "Cat $\rightarrow$ Dog" translation tasks, pix2pix-zeroCon achieved a BG-LPIPS score of 0.0265 (where lower indicates better structure preservation), significantly outperforming p2p-zero (0.0944). Simultaneously, it maintained a high CLIP-Score (0.2747), confirming that the edits align strongly with the target text prompts.

Qualitative Analysis

Visual results demonstrate that pix2pix-zeroCon preserves backgrounds, lighting, and fine details—such as the specific weave of a basket or the reflection on a ceramic mug—almost perfectly. Unlike competing models that might change the pose of a subject or the color of the background, our method restricts changes strictly to the target concept.

A comprehensive suite of qualitative results showing pix2pix-zeroCon's performance across various domains, from object swaps to seasonal changes.

Conclusion and Future Work

The primary insight of this research is that the internal layers of the diffusion U-Net are sufficient for contrastive learning, effectively acting as their own structural critics. By avoiding fine-tuning, this approach is significantly faster and more accessible for real-time applications.

However, a remaining challenge is Object Addition and Removal. When the model is tasked with adding a new object or removing an existing one, it occasionally struggles with background consistency or perspective. Future research will investigate methods to better "hallucinate" background details in these more transformative editing scenarios.

Summary updated

BibTeX
@misc{si2025contrastive,
  author = {Qi Si and Bo Wang and Zhao Zhang},
  title = {{Contrastive Learning Guided Latent Diffusion Model for Image-to-Image Translation}},
  year = {2025},
  eprint = {2503.20484},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.20484},
}
Figure