๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #191

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?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Image Segmentation โ€“ FAQs

Quick answers about learning Image Segmentation in Deep Learning.

This free note from CodingNow 2.0 explains Image Segmentation in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Image Segmentation, is 100% free with no signup required.
With focused practice, most students grasp Image Segmentation in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now