Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Convolutions for both players
The first GANs used plain fully connected networks and produced blurry, unstable results on images. DCGAN rebuilt both players from convolutions. The discriminator shrinks an image step by step, like a normal image classifier. The generator does the reverse: it starts from a tiny 4 × 4 block of features made from noise and doubles the size at every layer until it reaches a full image. A handful of rules about normalisation, activations and the optimizer made this train reliably. The demo shows one detail of the upsampling step: some kernel sizes cover the output unevenly and leave a faint checkerboard pattern.
DCGAN-style generators are small enough to train on a laptop and still appear in data augmentation for small sensor images, for example infrared patches or spectrogram tiles, and as a baseline when testing new GAN ideas.
- 1. The DCGAN generator upsamples with…
- 2. The DCGAN discriminator downsamples with…
- 3. A 4 × 4 seed doubled four times becomes…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Architecture rules (Radford et al. 2016). Replace pooling with strided convolutions (D) and fractionally strided, that is transposed, convolutions (G). Remove fully connected hidden layers: G projects z with one matrix multiply to a 4 × 4 × 1024 tensor; D flattens the last feature map into one sigmoid output.
- Normalisation. Batch norm in both networks, except the G output layer and the D input layer (applying it there caused oscillation and instability).
- Activations. ReLU in G, tanh at its output (images scaled to [−1, 1]); LeakyReLU with slope 0.2 in D.
- Optimisation. Adam with learning rate 0.0002 and β1 = 0.5 (0.9 oscillated); batch 128; weights from N(0, 0.02).
- 64 × 64 generator. z (100) → 4 × 4 × 1024 → 8 × 8 × 512 → 16 × 16 × 256 → 32 × 32 × 128 → 64 × 64 × 3. The original code used 5 × 5 kernels; the PyTorch example uses kernel 4, stride 2, padding 1.
- Shapes. Strided conv: L_out = ⌊(L_in + 2p − k)/s⌋ + 1. Transposed conv: L_out = (L_in − 1)s − 2p + k (+ output padding). k = 4, s = 2, p = 1 exactly doubles or halves.
- Checkerboards (Odena, Dumoulin and Olah 2016). If k is not divisible by s, output positions receive different numbers of kernel taps, which leaves a periodic pattern. Fixes: k divisible by s, or nearest-neighbour upsampling followed by a convolution (used by StyleGAN and most later generators).
- Findings. Smooth walks in z space; vector arithmetic (smiling woman − neutral woman + neutral man ≈ smiling man, averaging three z per concept); D features gave 82.8% CIFAR-10 accuracy with a linear SVM.
- 1. DCGAN used Adam with β1 =…
- 2. Batch norm is NOT applied to…
- 3. Checkerboard artifacts appear when…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Shapes, adjoints and overlap
Exercise 1.
- Output lengths of strided and transposed convolutions.
- A 1-D transposed convolution written as a loop, and a check that it is the adjoint of the strided convolution with the same kernel.
- Overlap counts showing even coverage for k = 4, s = 2 and a checkerboard for k = 3, s = 2.
Practice.
- Start from a reference implementation (the PyTorch DCGAN example or torchvision models) and change one thing at a time.
- Use k divisible by s or resize-then-convolve in the generator to avoid checkerboards.
- Batch norm caveats: each batch should be all real or all fake for D, or switch to spectral normalisation (E5.7), which later work found more robust.
- Monitor FID on a fixed sample, and save sample grids from a fixed z every epoch to spot collapse early.
- For serious image quality in 2026 use StyleGAN2-ADA or a diffusion model; DCGAN remains the standard small baseline.
import torch.nn as nn
def G(nz=100, ngf=64):
blk = lambda i, o, s, p: [nn.ConvTranspose2d(i, o, 4, s, p, bias=False), nn.BatchNorm2d(o), nn.ReLU(True)]
return nn.Sequential(*blk(nz, ngf * 8, 1, 0), *blk(ngf * 8, ngf * 4, 2, 1), *blk(ngf * 4, ngf * 2, 2, 1),
*blk(ngf * 2, ngf, 2, 1), nn.ConvTranspose2d(ngf, 3, 4, 2, 1, bias=False), nn.Tanh())
def D(ndf=64):
blk = lambda i, o, bn: [nn.Conv2d(i, o, 4, 2, 1, bias=False)] + ([nn.BatchNorm2d(o)] if bn else []) + [nn.LeakyReLU(0.2, True)]
return nn.Sequential(*blk(3, ndf, False), *blk(ndf, ndf * 2, True), *blk(ndf * 2, ndf * 4, True),
*blk(ndf * 4, ndf * 8, True), nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=False))
# Adam(lr=2e-4, betas=(0.5, 0.999)) for both; weights init N(0, 0.02)- 1. To avoid checkerboards use…
- 2. A robust alternative to batch norm in D is…
- 3. The PyTorch DCGAN generator's first layer maps z to…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Transposed convolution as an adjoint. A strided convolution is a linear map T from inputs to outputs. Its transpose Tᵀ maps outputs back to inputs: every input position scatters its value times the kernel into a window of the output. That is exactly the transposed convolution, and ⟨T x, v⟩ = ⟨x, Tᵀ v⟩. It is not an inverse; it only restores the shape.
Overlap. With stride s and kernel k, output position o receives taps from the inputs i with o = i·s + j − p for some 0 ≤ j ≤ k − 1. When s divides k every interior output gets k/s taps. Otherwise the count alternates between ⌊k/s⌋ and ⌈k/s⌉, and even a constant input produces a striped (1-D) or checkerboard (2-D) output. Training can learn to cancel this, but the pattern often survives as an artifact.
Why the rules helped. Strided convolutions let both networks learn their own down- and upsampling. Batch norm keeps activations well scaled in deep generators and was reported to reduce collapse onto a single point. LeakyReLU keeps gradients flowing from D to G for inputs D rejects. Adam with β1 = 0.5 averages momentum over about two steps rather than ten, so it reacts faster in a game where the other player keeps moving.
Inductive bias. Convolutions share weights across positions and are equivariant to translation (up to stride effects). For data whose content can appear anywhere this needs far fewer parameters than a dense layer; whether it improves sample quality depends on the data and on scale.
- 1. A transposed convolution is the…
- 2. With k = 3 and s = 2 interior outputs receive…
- 3. β1 = 0.5 means momentum averages over about…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Do convolutions buy better samples, or only fewer parameters, on a small 1-D problem?
History.
- A. Radford, L. Metz and S. Chintala, “Unsupervised representation learning with deep convolutional generative adversarial networks” (ICLR 2016).
- A. Odena, V. Dumoulin and C. Olah, “Deconvolution and checkerboard artifacts” (Distill 2016).
- T. Salimans et al., “Improved techniques for training GANs” (NeurIPS 2016): feature matching, minibatch discrimination, the Inception Score.
Exercise 2. “Sensor pulses”: 16-sample signals containing one Gaussian bump (width 1.5) at a uniform random position in [2, 13] with amplitude uniform in [0.5, 1], plus noise of std 0.03.
- DCGAN-style: G is a dense layer z (8) → 8 channels × 4, then two transposed convolutions (k = 4, s = 2, p = 1) to 8 × 8 and 1 × 16. D mirrors it with two strided convolutions and a dense output. LeakyReLU(0.2) everywhere, no batch norm.
- MLP: G 8 → 32 → 64 → 16, D 16 → 64 → 32 → 1.
- Training: non-saturating loss, Adam (lr 0.002, β1 = 0.5), batch 64, 1000 steps; convolutions are dense matrices built from shared weights by an index map.
- Measures on 1000 samples: median RMS residual after fitting the best single pulse; total-variation distance between the fitted positions and the uniform distribution; how many of 11 position bins are covered.
| model | parameters (G + D) | residual (seed 0 / 1 / 2) | position TV (seed 0 / 1 / 2) | bins covered |
|---|---|---|---|---|
| real data | – | 0.0276 / 0.0278 / 0.0276 | – | – |
| DCGAN-style | 585 + 337 | 0.036 / 0.0421 / 0.0401 | 0.108 / 0.068 / 0.084 | 11 / 11 / 11 |
| MLP | 3440 + 3201 | 0.0297 / 0.0311 / 0.0349 | 0.122 / 0.093 / 0.071 | 11 / 11 / 11 |
- Same job with 6–9× fewer parameters: the convolutional GAN produced single clean pulses at every position, with no mode collapse.
- No quality gain: the MLP fitted pulse shapes slightly better on every seed; position coverage was similar (TV 0.07–0.12 for both). Mean amplitude was about 0.67–0.70 for DCGAN and 0.70–0.75 for the MLP against 0.75 in the data.
- Round-off matters: the same code run in the browser (Pyodide, no BLAS) gives slightly different numbers, for example seed 0 DCGAN residual 0.0357 and TV 0.112 instead of 0.036 and 0.108. GAN training amplifies tiny floating-point differences, so only the second digit and the conclusions are reproducible across machines.
- Caveat: 16 samples is tiny. DCGAN’s advantage in the paper came from 64 × 64 images, where a dense generator would need millions of parameters and has no locality prior.
DCGAN in AI, robotics and aerospace
- Small-image augmentation: DCGAN-style generators have been used for infrared, SAR and spectrogram patches where data are scarce, usually as a baseline before larger models.
- Representation learning: the discriminator’s features were an early demonstration of unsupervised feature learning, later overtaken by self-supervised methods (E16).
- Architecture heritage: strided convolutions, LeakyReLU in D and Adam with β1 = 0.5 or 0 remain default choices in later GANs.
References
- A. Radford, L. Metz and S. Chintala (2016). “Unsupervised representation learning with deep convolutional generative adversarial networks.” ICLR.
- A. Odena, V. Dumoulin and C. Olah (2016). “Deconvolution and checkerboard artifacts.” Distill.
- V. Dumoulin and F. Visin (2016). “A guide to convolution arithmetic for deep learning.” arXiv.
- T. Salimans, I. Goodfellow, W. Zaremba, V. Cheung, A. Radford and X. Chen (2016). “Improved techniques for training GANs.” NeurIPS.