Advanced level · Module 2: Generative Models · Lesson 1 of 4
Autoencoders and Latent Spaces
Compress data into a latent representation and reconstruct it, and use reconstruction error to detect anomalies.
In this lesson you will
- Build an autoencoder in PyTorch
- Use reconstruction error for anomaly detection
Key concepts
encoder and decoderlatent spacereconstruction lossanomaly detection
The lesson
An autoencoder learns to compress inputs into a small latent vector (the encoder) and rebuild them (the decoder), trained to minimise reconstruction error.
The latent space captures the main variations in the data. Similar inputs end up close together, which is useful for visualisation and search.
Trained on normal examples only, an autoencoder reconstructs unusual inputs poorly — a high reconstruction error flags possible anomalies, such as faulty solar panels in inspection photos.
Step by step
- Build and train an autoencoder on normal images.
- Visualise reconstructions.
- Compute reconstruction errors for normal and abnormal images.
- Choose a threshold for flagging anomalies.
Practice activity
Build the anomaly detector from the practical activity.
Expected result: A working detector with a justified threshold and examples.
Check your understanding
-
What does an autoencoder learn to do?
Show answer
Compress inputs and reconstruct them.
-
Why does high reconstruction error suggest an anomaly?
Show answer
The model was trained on normal data and reconstructs unusual inputs poorly.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.