Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Shrink the picture, then grow it back
A convolutional autoencoder works like a zoom-out and zoom-in. The encoder slides small filters over the image and halves its size several times, ending with a small stack of feature maps: the code. The decoder reverses this, doubling the size at each step until it gets back to a full image. Because the same filters are used everywhere, a pattern learned in one corner works in every corner. The demo shows the sizes along the way.
Convolutional autoencoders compress and clean images, spectrograms and sensor grids, detect visual defects, and form the image compressors inside latent diffusion models.
- 1. The encoder of a convolutional autoencoder…
- 2. The decoder uses…
- 3. Weight sharing means a pattern is handled…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Convolution output size: ⌊(n + 2p − k)/s⌋ + 1.
- kernel 4, stride 2, padding 1 halves the size: 28 → 14;
- kernel 5, stride 2, padding 2 turns 32 into 16.
- Transposed convolution output size: (n − 1)s − 2p + k + output padding.
- 16 with kernel 4, stride 2, padding 1 gives 32;
- 7 with kernel 3, stride 2, padding 1 and output padding 1 gives 14.
- Parameters: c_in · c_out · k² + c_out per 2-D convolution (3 → 16 channels with 3 × 3 kernels: 448).
- Code size: 28 × 28 inputs after two halvings with 32 channels give 7 × 7 × 32 = 1568 numbers. The code shrinks spatially but grows in channels.
- Exercise 2’s models: dense [32, 16, 32] has 1072 parameters; the convolutional one has a 5-tap kernel and a bias each way, 12 parameters.
- 1. conv_out(28, k=4, s=2, p=1):
- 2. tconv_out(16, k=4, s=2, p=1):
- 3. Parameters of a 3 → 16, 3 × 3 convolution:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Convolutional autoencoders in code
Exercise 1.
- The convolution and transposed-convolution size formulas matched the examples.
- A 1-D cross-correlation with kernel (1, 0, −1) gave constant −2 on a ramp.
Practice.
- Use
nn.Conv2d(..., stride=2)down andnn.ConvTranspose2d(..., stride=2)up, with batch norm or group norm and ReLU or GELU. - To avoid checkerboard artefacts, prefer
nn.Upsamplefollowed by a convolution, or choose kernel sizes divisible by the stride. - For high-quality reconstructions, add perceptual or adversarial losses, as in the VQGAN and latent-diffusion autoencoders.
enc = nn.Sequential(nn.Conv2d(1, 16, 4, 2, 1), nn.ReLU(), nn.Conv2d(16, 32, 4, 2, 1)) # 28 → 14 → 7
dec = nn.Sequential(nn.ConvTranspose2d(32, 16, 4, 2, 1), nn.ReLU(), nn.ConvTranspose2d(16, 1, 4, 2, 1))
loss = F.mse_loss(dec(enc(x)), x)- 1. Checkerboard artefacts come from…
- 2. A fix for checkerboards:
- 3. Latent diffusion's autoencoder adds…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Equivariance.
- Convolution commutes with translation: shifting the input shifts the feature map (exactly for stride 1, up to the stride for strided layers).
- An autoencoder built from convolutions therefore reconstructs a shifted pattern the way it reconstructs the original.
- What it learns at one position transfers to all positions.
Fewer parameters, better generalisation.
- A dense layer needs separate weights for every input–output pair. A convolution shares a small kernel.
- This acts as a strong, correct prior for images and signals, where the same local patterns appear everywhere.
- The model needs far less data and cannot memorise position-specific quirks.
Limits. Strided layers are only approximately shift-equivariant (aliasing). Pure convolutions see only a local window, so long-range structure needs depth, pooling or attention.
- 1. Convolution commutes with…
- 2. Strided layers are shift-equivariant…
- 3. Long-range structure needs…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Does weight sharing let an autoencoder handle patterns in unseen positions?
History.
- J. Masci, U. Meier, D. Cireşan and J. Schmidhuber, “Stacked convolutional auto-encoders for hierarchical feature extraction” (ICANN 2011).
- A. Odena, V. Dumoulin and C. Olah, “Deconvolution and checkerboard artifacts” (Distill 2016).
- Convolutional autoencoders are the compression stage of latent diffusion models (Rombach and colleagues, 2022).
Exercise 2.
- Data: 1-D signals of length 32 with two Gaussian bumps. Training bumps lie only in the left half; the test uses bumps in the left half and in the unseen right half.
- Models, both 32 → 16 (tanh) → 32, trained for 1500 Adam steps:
- a dense autoencoder;
- a convolutional one with a shared 5-tap kernel, stride 2 down and a transposed convolution up.
- Measurement: relative reconstruction error (squared error divided by signal energy).
| model | parameters | error, left half (seen) | error, right half (unseen) |
|---|---|---|---|
| dense | 1072 | 0.0004 | 4.458 |
| convolutional | 12 | 0.030 | 0.088 |
- The dense autoencoder memorises positions: it fits the training region almost perfectly but fails completely in the right half, worse than outputting zeros (error 1). It never learned weights for those positions.
- The convolutional autoencoder generalises with 89 times fewer parameters: the same kernel handles bumps wherever they are. Its right-half error is close to its left-half error.
- The price is a less exact fit on the seen region (0.030 against 0.0004): 12 parameters cannot capture every detail.
- Seeds: with seeds 1 and 2, the unseen-half errors were 4.63 and 3.41 for dense against 0.038 and 0.028 for convolutional.
Convolutional autoencoders in AI, robotics and aerospace
- Visual inspection: reconstruction-based defect detection on production lines and aircraft surfaces.
- Imaging and spectra: denoising satellite images, radar and spectrograms; compressing images for downlink.
- Generative pipelines: latent diffusion models encode images with a convolutional autoencoder before diffusion.
- Design lesson: build the symmetries of your data into the architecture. It saves parameters and makes behaviour on unseen cases predictable.
References
- J. Masci, U. Meier, D. Cireşan and J. Schmidhuber (2011). “Stacked convolutional auto-encoders for hierarchical feature extraction.” ICANN.
- A. Odena, V. Dumoulin and C. Olah (2016). “Deconvolution and checkerboard artifacts.” Distill.
- R. Rombach et al. (2022). “High-resolution image synthesis with latent diffusion models.” Proc. CVPR.