DCGAN
DCGAN showed that a generator built only from strided convolutions and batch normalisation can learn to draw convincing bedroom photos from random noise.
Why Does This Exist?
The original GAN proved the game could work but gave almost no architectural guidance. Generators built from fully connected layers produced blurry digits and collapsed constantly, and nobody knew which choices mattered. Scaling to real photos looked hopeless.
DCGAN replaced folklore with a recipe. All-convolutional stacks, strided convolutions instead of pooling, batch normalisation almost everywhere, ReLU in the generator with Tanh at the output, LeakyReLU in the discriminator. On bedroom photos those rules produced the first GAN samples that looked like places rather than textures. Every convolutional GAN after it, including conditional GAN and the paired translator Pix2Pix, starts from this template.
Think of It Like This
Developing a photo from a thumbnail sketch
A darkroom printer starts from a tiny blurry thumbnail and enlarges it in stages. Each enlargement doubles the size while adding finer grain, and a chemical bath between stages keeps contrast stable so no stage blows out to white or black.
The noise vector is the thumbnail. Each strided transposed convolution doubles the resolution, and batch normalisation is the stabilising bath. Skip the bath and contrast explodes by the fourth doubling, which is exactly the training collapse the recipe prevents.
How It Actually Works
The generator takes , a -dimensional vector of uniform noise, projects it to , then applies four fractionally-strided convolutions that double spatial size while quartering depth: . The discriminator mirrors this with strided convolutions down to a single real-or-fake score. No pooling, no fully connected hidden layers anywhere.
The activation rules carry real weight. Batch normalisation on every layer except the generator output and discriminator input keeps activations centred as the game shifts underneath both networks. ReLU lets the generator build unbounded bright features, Tanh bounds the final photo to , and LeakyReLU with slope keeps discriminator gradients alive for negative inputs where plain ReLU would go silent.
Worked example
First generator layer: project noise numbers to values. That matrix holds parameters, more than the rest of the generator combined, which is why later work shrank this projection first. Each doubling stage then roughly quarters parameters while quadrupling pixels, so capacity concentrates exactly where the image is smallest and most abstract.
Code
Shape trace of the generator, the quick check that catches a miswired doubling stage.
def dcgan_shapes(z_dim: int = 100) -> list[tuple[int, int, int]]: """Spatial shapes through the four doubling stages.""" shapes = [(4, 4, 1024)] h, w, c = shapes[0] for _ in range(4): # each stage doubles size, quarters depth h, w, c = h * 2, w * 2, max(c // 4, 3) shapes.append((h, w, c)) return shapes
print(dcgan_shapes()) # -> [(4, 4, 1024), (8, 8, 256), ..., (64, 64, 3)]print(100 * 4 * 4 * 1024) # -> 1638400 first-layer parametersWatch Out For
Removing batch normalisation to save memory
The recipe's most load-bearing rule is batchnorm everywhere except the two boundary layers. Drop it and the generator's activations drift as the discriminator improves, gradients explode by the third doubling, and samples collapse to a single texture within epochs.
If memory forces a change, swap in instance or layer normalisation, never nothing. Unnormalised DCGAN at pixels is the canonical collapse demo.
Feeding photos in [0, 1] to a Tanh output
The generator output passes through Tanh, so it lives in . Normalise training photos to and the discriminator separates real from fake by range alone in the first epoch, then never learns anything about content.
Scale real images to to match. This one-line mismatch has wasted more GAN training runs than any architecture choice.
The Quick Version
- DCGAN builds both networks from strided convolutions only, no pooling or dense hidden layers.
- A -dimensional noise vector grows through four doublings into a photo.
- Batch normalisation on all but two layers plus ReLU, LeakyReLU, and Tanh makes training stable.
- The first projection matrix alone holds parameters.
- Match real images to the Tanh range or the discriminator cheats on range alone.