Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Deep Learning Notes
Topic #380

Image Segmentation

Image segmentation pushes computer vision to its finest level of spatial detail: instead of a whole-image label (classification) or a box (detection), it assigns a class label to every individual pixel in the image.

Why Pixel-Level Prediction Is a Different Kind of Problem

A classification network collapses spatial information down to one label (via pooling/GAP, see Global Average Pooling). Segmentation needs the exact opposite: a full-resolution output map, the same spatial size as the input, with a class prediction at every position. This requires architectures specifically designed to preserve (or later restore) spatial resolution, rather than discarding it — the direct motivation behind the FCN and U-Net architectures covered later in this category.

Three Flavors, Introduced Here

FlavorWhat It Distinguishes
Semantic segmentationEvery pixel gets a class label, but individual object instances of the same class aren't distinguished from each other
Instance segmentationEvery pixel gets both a class label AND a specific object instance ID, distinguishing separate objects of the same class
Panoptic segmentationUnifies both — assigns instance IDs to countable "things" (objects) while still labeling uncountable "stuff" (sky, road, grass) semantically

Each of these gets its own dedicated note next, but the shared foundation is exactly this idea: a per-pixel prediction task, evaluated with metrics like IoU and Dice (see Dice Score) rather than whole-image accuracy.

Code — The Output Shape Difference

import torch

# Classification output: one label per whole image
classification_output_shape = (1, 10)   # (batch, num_classes)

# Segmentation output: one label PER PIXEL
segmentation_output_shape = (1, 10, 224, 224)   # (batch, num_classes, H, W)
# argmax over dim=1 gives the predicted class for every individual pixel

Common Mistakes

  • Applying standard classification evaluation metrics (like whole-image accuracy) to a segmentation task — pixel-level metrics like IoU and Dice are the appropriate tools here, not whole-image classification metrics.
  • Confusing which segmentation flavor a specific task actually needs — the choice between semantic, instance, and panoptic segmentation has real architectural consequences, covered in the next three notes.

Interview Relevance

Q: "Why can't a standard image classification CNN, as-is, perform image segmentation?" Classification architectures deliberately collapse spatial information into a single whole-image prediction, typically via pooling or Global Average Pooling. Segmentation needs the opposite — a full-resolution, per-pixel output — which requires architectures specifically designed to preserve or restore spatial detail throughout the network, rather than discarding it for a single final classification.

Practice Question

An image of a street scene contains three cars. Would semantic segmentation alone be able to tell you there are three separate cars? Why or why not?

Related DL Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's Deep Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →