The Right Losses for the Right Gains: Improving the Semantic Consistency of Deep Text-to-Image Generation with Distribution-Sensitive Losses

Mahmoud Ahmed, Omer Moussa, Ismail Shaheen, Mohamed Abdelfattah, Amr Abdalla, Marwan Eid, Hesham Eraqi, Mohamed Moustafa

TL;DR

This paper introduces a contrastive learning framework for text-to-image (T2I) synthesis that tackles semantic inconsistency caused by highly diverse human captions. By combining a novel "fake-to-fake" loss and a "fake-to-real" loss, the proposed method aligns the distributions of generated and real images, resulting in a massive 44% improvement in FID score over the baseline SSAGAN model on the challenging MS COCO dataset.

What Problem Does This Paper Address?

Generative Adversarial Networks (GANs) for text-to-image synthesis often struggle with semantic consistency. In standard datasets, a single image typically has multiple human-authored captions that vary wildly in word choice, structure, and detail. When a model trains on these diverse descriptions, it struggles to map the textual and visual domains accurately, often generating images that are semantically dissimilar to each other or missing fine-grained details.

Furthermore, existing models that manage to capture fine details are often parameter-heavy and inefficient, while lighter models tend to produce blurry or "washed-out" images. The authors aim to bridge this gap by improving both the visual quality and the semantic controllability of T2I generation without exploding the model's parameter count.

Methods

The authors tackle the problem from two distinct angles: architectural modifications and novel distribution-sensitive loss functions.

  1. Architectural Modifications: They experiment with integrating StyleGAN2 blocks into the attentional mechanism of AttnGAN (termed AttnGAN with Style Blocks), replacing standard generator and discriminator blocks to better capture both coarse and fine-grained image features.
Figure 1: AttnGAN with Style Blocks
  1. Distribution-Sensitive Contrastive Losses: Applied to the single-generator SSAGAN architecture, the authors introduce a dual-flavor contrastive learning framework using the Normalized Temperature-scaled Cross-Entropy (NT-Xent) loss:
  2. Fake-to-Fake (F2F) Loss: Minimizes the distance between the encodings of two fake images generated from different captions describing the same underlying real image. This forces the model to maintain semantic consistency despite linguistic variations.
  3. Fake-to-Real (F2R) Loss: Minimizes the distance between the encodings of the generated (fake) images and their corresponding ground-truth (real) images, closing the distribution gap between real and synthetic data.
  4. Image Re-captioning Loss: An auxiliary loss that uses a captioning model to ensure the generated image retains features that can be mapped back to the original text prompt.
Figure 3: Contrastive Loss Architecture

Datasets

The approach was evaluated on two widely used benchmarks:

  • CUB-200 (Caltech-UCSD Birds 200): A dataset containing roughly 13,000 images across 200 bird species. Because it focuses on a single category, it provides a simpler mapping space for evaluating fine-grained details.
  • Microsoft Common Objects in Context (MS COCO): A significantly more complex, large-scale dataset consisting of 328,000 images across 80 diverse object categories, presenting a much stiffer challenge for semantic convergence.

Key Insights and Ideas

  • The StyleGAN Paradox: While fusing StyleGAN2 blocks into AttnGAN dramatically improved the qualitative sharpness and fine details of the images, it actually worsened automated metrics like Frechet Inception Distance (FID) and Inception Score (IS). The authors discovered this was due to low output variance; the style mapping network caused the generator to ignore unmentioned features (like poses or backgrounds), leading to mode collapse-like behavior in distribution metrics despite high visual quality.
  • Anchoring Semantics via Images: Instead of relying solely on text-to-image matching losses (like DAMSM), contrastive learning on the image-to-image side (F2F and F2R) acts as a powerful regularizer. It ensures that linguistic variations in prompts don't cause the generator to drift away from the core visual concepts.

Key Results

The quantitative evaluation demonstrated substantial improvements when combining both contrastive losses (R2F + F2F):

  • MS COCO Dataset: The SSAGAN + CL (R2F + F2F) model achieved an FID score of 10.89, outperforming the baseline SSAGAN (19.37) by 44%. It also boosted the R-precision from 82.45% to 88.21%, showing a much tighter correlation between the text prompt and the generated image.
  • CUB Dataset: The same combination yielded an FID of 9.12 (compared to 9.76 for baseline SSAGAN) and achieved the highest Inception Score (5.18) among the tested variants.

Limitations and Future Work

The primary limitation identified is the low diversity/variance in the StyleGAN-modified architectures. Because the network focuses heavily on text-specified features, it struggles to generate diverse backgrounds and poses, which penalizes its FID and IS scores.

Additionally, due to severe hardware and time constraints, the authors could not train all architectural permutations (such as the StyleGAN-modified AttnGAN variants) on the massive MS COCO dataset. Future work will likely focus on resolving the variance issues in style-based text-to-image generators to match their high qualitative output with strong quantitative metrics.

Summary updated

BibTeX
@misc{ahmed2023right,
  author = {Mahmoud Ahmed and Omer Moussa and Ismail Shaheen and Mohamed Abdelfattah and Amr Abdalla and Marwan Eid and Hesham Eraqi and Mohamed Moustafa},
  title = {{The Right Losses for the Right Gains: Improving the Semantic Consistency of Deep Text-to-Image Generation with Distribution-Sensitive Losses}},
  year = {2023},
  eprint = {2312.10854},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.10854},
}
Figure