Deep Unsupervised Learning

Image Inpainting with Autoencoders

AutoencoderU-NetMSE
Image Inpainting with Autoencoders
Problem

Image inpainting asks a model to reconstruct missing pixels from corrupted input. The core question is whether a bottleneck autoencoder can learn a compact latent code that still preserves enough spatial detail to recover structure and colour—and whether skip connections materially improve that recovery on small 32×32 natural images.

Dataset

CIFAR-10 train and test splits (32×32 RGB). Each sample is corrupted on the fly: 1–9 random lines drawn with OpenCV (thickness 1–2) and applied via a binary mask, producing a masked input paired with the original clean image. Pixels are scaled to [0, 1] with ToTensor(). The mask itself is not fed to the model—only the corrupted image.

Approach

I implemented two reconstruction models trained with the same objective. The baseline is a plain convolutional autoencoder: three stride-2 conv blocks down to a 64×4×4 bottleneck, then transposed convolutions back to 32×32 with a sigmoid output. The second model follows a U-Net-style design: a deeper encoder (128×8×8 bottleneck) with skip connections concatenated into the decoder so fine-grained spatial features bypass the bottleneck. Both predict the full clean image from the masked input using per-pixel MSE.

Training

Adam optimizer, learning rate 0.001, batch size 128, 100 epochs, MSE loss. Training uses only the masked image as input; supervision is the uncorrupted target. Each epoch logs average reconstruction loss on the training set.

My Work
  • Built a custom Dataset that applies random line-mask corruption and returns (masked_input, mask, original) tuples
  • Implemented Autoencoder_Simple (3→16→32→64 encoder; symmetric transposed-conv decoder)
  • Implemented Autoencoder_UNet with encoder–decoder skip connections for sharper inpainting
  • Wrote separate training loops for both models with per-epoch average MSE logging
  • Visualized 10 held-out test samples as corrupted input → reconstruction → ground truth for each architecture
Evaluation
  • 10 held-out CIFAR-10 test images with on-the-fly random line corruption (same mask pattern per sample)
  • Simple conv autoencoder: corrupted input → reconstruction → ground truth
  • U-Net autoencoder: corrupted input → reconstruction → ground truth on identical samples
Simple autoencoder inpainting on corrupted CIFAR-10 test images
Simple AE — corrupted input → reconstruction → ground truth (10 test samples)
U-Net autoencoder inpainting on corrupted CIFAR-10 test images
U-Net AE — corrupted input → reconstruction → ground truth (10 test samples)
Results
  • Simple autoencoder — final average MSE: 0.00748 (epoch 100)
  • U-Net autoencoder — final average MSE: 0.00106 (epoch 100), ~7× lower than the baseline
  • Qualitative: U-Net recovers edges and colour more faithfully on line-corrupted regions
Training MSE loss curves for autoencoder models
Training MSE over 100 epochs — simple AE vs. U-Net
Takeaway

Skip connections are not decorative—they carry spatial detail that a narrow bottleneck otherwise washes out. The U-Net cut MSE by an order of magnitude and looked visibly sharper on corrupted lines. This was my first concrete lesson that architecture (inductive bias) can matter as much as loss choice for pixel-level reconstruction.

Work completed during Oxford summer coursework. This page shows only my own implementations and outputs; course materials are not redistributed.