Model · Oct 2026 · runs in your browser
DCGAN
The VAE learns to reconstruct its inputs. A GAN never sees a reconstruction loss: a generator turns random numbers into images, a discriminator tries to tell them from real digits, and each is trained to beat the other. When it works, the generator ends up drawing digits that were never in the data.
- Generator parameters
- 546,177
- Latent size
- 64
- Model file
- 2185 KB, ONNX
- Training time
- 2.9 min, GPU
Try it
Every image is drawn from 64 random numbers by the generator, in your browser. Nothing here was in the training set.
Judging a GAN
A GAN has no test loss. Instead, 10,000 samples from the exported generator were shown to the small CNN from this zoo, which never saw a generated image.
| Metric | Value | Source |
|---|---|---|
| Share of samples per digit, as read by the CNN (10% each would be perfectly even) | 7.5% to 12.9% | public/models/dcgan-mnist/meta.json |
| Entropy of that distribution (log2 10 = 3.32 bits is the maximum) | 3.30 bits | public/models/dcgan-mnist/meta.json |
| CNN's mean confidence on generated digits | 86.2% | public/models/dcgan-mnist/meta.json |
| CNN's mean confidence on real test digits | 99.0% | public/models/dcgan-mnist/meta.json |
| Fréchet distance in the CNN's features: real vs generated | 0.004 | public/models/dcgan-mnist/meta.json |
| Same distance between two halves of the real test set (the floor) | 0.002 | public/models/dcgan-mnist/meta.json |
The Fréchet distance is the idea behind FID, computed on the CNN's 16 pooled feature channels instead of Inception's 2,048, so it is only comparable within this page, not with published FID numbers.
Training run
Neither loss goes to zero: the two networks keep pushing against each other. A discriminator that wins outright would leave the generator with no useful gradient.
How it works
Generator. 64 random numbers go through a linear layer to a 128-channel 7×7 map, then two transposed convolutions upsample to 14×14 and 28×28, with batch norm and ReLU, and tanh at the end, following Radford et al. (2016).
Discriminator. Two strided convolutions with leaky ReLU, then one linear output: real or generated.
Training. Alternate one discriminator step and one generator step per batch of 128, Adam with learning rate 0.0002 and β1 = 0.5, 30 epochs. The generator uses the non-saturating loss: it maximises the discriminator's belief that its images are real, which gives stronger gradients early on than minimising the belief that they are fake.
Reproduce
- Hardware
- NVIDIA GeForce RTX 3050 Laptop GPU, PyTorch 2.6.0+cu124
- Commit
- 94eae73
- Data
- MNIST, 60,000 training images
Environment
pip install torch numpy onnx onnxruntimeTrain, export, judge with the CNN
python training/dcgan_mnist/train.py