Tathagat Agrawal

Semantic segmentation with U-Net

A U-Net written in PyTorch that separates pets from the background in Oxford-IIIT Pet images, pixel by pixel.

July 2025 · Complete · Source on GitHub

Result: Pixel accuracy on the training images rose from 75.9% to 91.9% over 10 epochs.

The problem

Semantic segmentation labels every pixel of an image. Here the task is binary: pet or background, on the Oxford-IIIT Pet dataset.

What I built

Result

Pixel accuracy on the training images rose from 75.9% after the first epoch to 91.9% after the tenth, with the loss still falling.

Two line charts: training accuracy rising from about 76% to 92% and training loss falling from 0.50 to 0.20 over 10 epochs.
Figure 1. Training accuracy and loss over 10 epochs.
Three rows of cat photos, each with its ground-truth mask and the model's predicted mask. The predictions capture the animal's overall shape but spill into nearby background.
Figure 2. Input images, ground-truth masks and the model's predictions. Images from the Oxford-IIIT Pet dataset (Parkhi et al., 2012, CC BY-SA 4.0).

Limits

The accuracy above is measured on the training images; the notebook does not score a held-out test split. The predicted masks get the overall shape right but blur edges and leak into similar-looking background, which more epochs, augmentation and a Dice or IoU metric would address.

Built with

Computer vision (CNNs, segmentation), PyTorch, Visualisation (Matplotlib, Seaborn, Power BI), Python