Abstract
Conditional image generation is the task of generating diverse images using class label information. Although many conditional Generative Adversarial Networks (GAN) have shown realistic results, such methods consider pairwise relations between the embedding of an image and the embedding of the corresponding label (data-to-class relations) as the conditioning losses. In this paper, we propose ContraGAN that considers relations between multiple image embeddings in the same batch (data-to-data relations) as well as the data-to-class relations by using a conditional contrastive loss. The discriminator of ContraGAN discriminates the authenticity of given samples and minimizes a contrastive objective to learn the relations between training images. Simultaneously, the generator tries to generate realistic images that deceive the authenticity and have a low contrastive loss. The experimental results show that ContraGAN outperforms state-of-the-art-models by 7.3% and 7.7% on Tiny ImageNet and ImageNet datasets, respectively. Besides, we experimentally demonstrate that contrastive learning helps to relieve the overfitting of the discriminator. For a fair comparison, we re-implement twelve state-of-the-art GANs using the PyTorch library.
Introduction: Beyond Data-to-Class Relations
Conditional image generation—creating specific types of images based on a category label—has traditionally relied on two primary strategies. Models like ACGAN utilize an auxiliary classifier to guide the generator, while models like ProjGAN employ a projection layer to align image embeddings with class embeddings.
However, these approaches share a fundamental limitation: they focus exclusively on data-to-class relations, treating each image-label pair in isolation. This narrow focus often leads to "discriminator overfitting," where the discriminator learns specific training samples rather than generalizable features, eventually causing training collapse. ContraGAN addresses this by incorporating data-to-data relations—understanding how different instances of the same class should relate to one another and differ from other classes.
Methodology: The Conditional Contrastive (2C) Loss
The core innovation of ContraGAN is the Conditional Contrastive (2C) loss. While standard contrastive learning (e.g., SimCLR) is typically unsupervised, ContraGAN adapts it for supervised generation.
- Hyperspherical Embedding Space: The discriminator serves as an encoder, mapping images into a high-dimensional hypersphere.
- The 2C Loss Mechanism: For any given image in a batch, the 2C loss pulls its embedding closer to its corresponding class embedding (the proxy) and closer to other images in the same batch sharing the same label. Simultaneously, it pushes the embedding away from images belonging to different classes.
- Dual Objective: The discriminator minimizes this loss to structure the feature space, while the generator aims to produce images that naturally fall into the correct clusters within this contrastive space.
Experimental Results
The authors evaluated ContraGAN against three standard benchmarks: CIFAR10, Tiny ImageNet, and ImageNet.
- Performance: ContraGAN achieved a significant performance boost, outperforming state-of-the-art models by 7.3% on Tiny ImageNet and 7.7% on ImageNet in terms of Frechet Inception Distance (FID).
- Stability: Stability tests against ProjGAN revealed that ContraGAN maintains high validation accuracy for longer periods, effectively mitigating the discriminator overfitting that typically leads to training collapse.
- Visual Fidelity: Qualitatively, ContraGAN produces images with sharper details and more coherent global structures, particularly in complex categories like landscapes and animals.
To facilitate future research, the authors also released PyTorch-StudioGAN, a comprehensive library re-implementing twelve state-of-the-art GANs under unified conditions.
Conclusion
By shifting the focus from simple pairwise image-label alignment to a more holistic relational learning approach, ContraGAN significantly improves the quality and stability of conditional image generation. The introduction of the 2C loss provides a powerful regularization effect, preventing discriminator overfitting and enabling the generation of more diverse and realistic images. Future work may explore the theoretical underpinnings of training collapse and further refine hyperparameter selection for contrastive objectives.
Summary updated