---
kind: concept
slug: conditional-batch-normalization
title: Conditional batch normalization
summary: >-
  Conditional batch norm normalizes features as usual, then scales and shifts them with values that depend on a conditioning input such as a sentence. The only card here is SD-GAN's semantic-conditioned batch norm, with a sentence cue or a word cue. Author-reported gains come only from ablations on a text-to-image GAN, and its cue-level numbers disagree across tables.
tags: [normalization, conditioning, text-to-image, gan]
papers: ["1904.01480"]
related: [generative-adversarial-network, contrastive-learning, adaptive-instance-normalization]
status: draft
updated_at: 2026-10-19
---

## Overview

Conditional batch normalization (cBN) keeps ordinary batch normalization and
adds a term that depends on a conditioning input. A generator layer can then
be steered by text without a separate branch for each caption.

Only one card on this wiki covers the concept: SD-GAN, which calls its version
semantic-conditioned batch norm (SCBN) [arxiv:1904.01480 §3.2]. This page
therefore describes that one paper. The shared structure is two steps. First,
each channel is normalized over the batch and spatial positions
[arxiv:1904.01480 eq. 3]. Second, the scale and shift are a learned value plus
a conditional value that comes from the input [arxiv:1904.01480 eq. 4].

## Variants

### Sentence-level cue

The conditional scale and shift come from the sentence vector through two
one-hidden-layer MLPs, one for each [arxiv:1904.01480 eq. 5]. The result is one
value per channel, applied across all spatial positions [arxiv:1904.01480 §3.2].
Author-reported, without the Siamese branch: CUB Inception score 4.39 ± .06 and
MS-COCO 28.81 ± .53 [arxiv:1904.01480 tab. 6]. Card:
[Semantics Disentangling for Text-to-Image Generation](/papers/1904.01480).

### Word-level cue

The conditional terms come from attention between each sub-region of the
feature map and the caption's word features [arxiv:1904.01480 eq. 6]
[arxiv:1904.01480 §3.2]. Two 1×1 convolutions turn the attended vectors into
scale and shift maps with the feature shape [arxiv:1904.01480 §3.2]. Author-reported,
without the Siamese branch: CUB 4.45 ± .06 and MS-COCO 29.79 ± .61
[arxiv:1904.01480 tab. 6]. Card: [Semantics Disentangling for Text-to-Image Generation](/papers/1904.01480).

## When to use which

The paper tests these choices in one setting only (text-to-image GANs on CUB
and MS-COCO), so the table ranks them on that setting's numbers.

| Situation | Use | Why |
|---|---|---|
| The conditioning is one vector per example | Sentence-level cue | Needs only the vector; no attention over positions [arxiv:1904.01480 eq. 5]. Author-reported 4.39 vs 4.45 on CUB for the word cue [arxiv:1904.01480 tab. 6] |
| Specific words, such as a colour, must reach the right image region | Word-level cue | Attention per sub-region over words [arxiv:1904.01480 eq. 6]. Author-reported 29.79 vs 28.81 on MS-COCO [arxiv:1904.01480 tab. 6]. Editing one word changes the expected colour or scene in their qualitative examples [arxiv:1904.01480 fig. 7] |
| The normalization layers cannot be changed | Plain batch norm with the cue concatenated, as a baseline only | Author-reported 4.19–4.23 on CUB and 24.18–25.34 on MS-COCO, below both cues [arxiv:1904.01480 tab. 6] |
| Training uses no Siamese caption pairs | Still apply SCBN | Author-reported gain without the pair loss: 4.11 → 4.49 on CUB and 23.76 → 29.79 on MS-COCO [arxiv:1904.01480 tab. 4] |

## Implementation sketch

The shared core normalizes, then modulates. Each cue function returns a
conditional scale and shift. The sentence and word cues differ only there.

```pseudocode
# Conditional batch norm, shared core  [eq. 3] [eq. 4]
# Input:  x (B, C, H, W); cond: sentence (B, D) or words (B, T, D)
# Output: (B, C, H, W)

def conditional_bn(x, cond, cue_fn):
    # Normalize each channel over batch and space  [eq. 3]
    x_hat = (x - mean(x)) / std(x)
    # Learned scale and shift, plus the conditional terms  [eq. 4]
    gamma_c, beta_c = cue_fn(x, cond)
    return (gamma + gamma_c) * x_hat + (beta + beta_c)
```

```pseudocode
# Sentence cue  [eq. 5] [§3.2]
# Input:  x (B, C, H, W); sentence (B, D)
# Output: gamma_c, beta_c (B, C, 1, 1), broadcast over H and W

def sentence_cue(x, sentence):
    # One-hidden-layer MLPs give one value per channel  [eq. 5]
    gamma_c = mlp_gamma(sentence)[:, :, None, None]
    beta_c = mlp_beta(sentence)[:, :, None, None]
    return gamma_c, beta_c
```

```pseudocode
# Word cue  [eq. 6] [§3.2]
# Input:  x (B, C, H, W); words (B, T, D_w)
# Output: gamma_c, beta_c (B, C, H, W)

def word_cue(x, words):
    # Project sub-regions and words to a shared size D  [§3.2]
    regions = embed_regions(x)                  # (B, L, D), L = H * W
    keys = project_words(words)                 # (B, T, D)
    # Softmax over words, per sub-region; axis implied, not written  [eq. 6]
    weights = softmax(regions @ keys.transpose(0, 2, 1), axis=-1)
    attended = weights @ keys                   # (B, L, D)
    # Two 1x1 convolutions give the modulation maps  [§3.2]
    feat = reshape_to_map(attended)             # (B, D, H, W)
    return conv_gamma(feat), conv_beta(feat)
```

## Contradictions

Three different numbers appear for "no Siamese branch, with SCBN". The paper
does not say which cue each table uses:

- Table 3, AttnGAN with SCBN: 4.48 ± .08 on CUB and 29.42 ± .45 on MS-COCO
  [arxiv:1904.01480 tab. 3].
- Table 4, row 3, SD-GAN without Siamese: 4.49 ± .06 on CUB and 29.79 ± .61 on
  MS-COCO [arxiv:1904.01480 tab. 4].
- Table 6, word cue without Siamese: 4.45 ± .06 on CUB and 29.79 ± .61 on
  MS-COCO [arxiv:1904.01480 tab. 6].

The gap is small on CUB (about 0.04) and larger on MS-COCO (about 0.37). The
paper gives no reason for the differences, and it does not say which cue
Table 4 uses.

## Papers

- [Semantics Disentangling for Text-to-Image Generation](/papers/1904.01480): SD-GAN, which adds semantic-conditioned batch norm to a stacked text-to-image GAN and a Siamese contrastive loss.
