liveBook · Manning

Image segmentation

As explained in Deep Learning with Python, Third Edition

A vision task that assigns a label to each pixel or region of an image, providing denser localization than object detection.

Image segmentation assigns a class to every pixel, partitioning an image into meaningful regions such as foreground and background, road, car, or sidewalk. Unlike object detection, which returns bounding boxes, segmentation provides pixel-level localization. section 11.1 section 11.1.1

Choose the segmentation flavor according to the detail you need:

  • Semantic segmentation labels each pixel by category; separate objects sharing a category receive the same label. section 11.1.1
  • Instance segmentation separates individual object instances, such as cat 1 and cat 2. section 11.1.1
  • Panoptic segmentation combines semantic and instance labels, assigning both kinds of information to every pixel. section 11.1.1

A foreground mask for pet images

The Oxford-IIIT Pets dataset pairs 7,390 cat and dog photographs with same-sized grayscale masks. Each mask stores foreground, background, and contour as integer values 1, 2, and 3. A practical pipeline downloads the archives, matches JPG inputs with PNG masks, resizes images to 200×200, loads arrays into memory, and creates training and validation splits. section 11.2.1

A segmentation model can be built by compressing an image with strided Conv2D layers and expanding the feature map with corresponding Conv2DTranspose layers until it returns a mask matching the input size. A pretrained Segment Anything model offers image, text, point, and box prompting when training from scratch is unnecessary. section 11.4

Figure 11.2 Semantic segmentation vs. instance segmentation
instance segmentation

Compare semantic and instance segmentation visually before choosing a labeling scheme. section 11.1.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains three segmentation types, dataset preparation, and encoder-decoder construction, while deferring detailed model internals.
Examples
Uses video-call background replacement, cat-and-dog masks, the Oxford-IIIT Pets dataset, and Segment Anything prompting.
What it assumes
Assumes an initial understanding of deep learning and binary image classification before extending computer vision to pixel-level prediction.
What you can do after
Builds a segmentation dataset and model from scratch or applies Segment Anything with image, text, point, or box prompts.
How it connects
Connects image classification and object detection as core computer vision tasks, and links masks to convolutional encoder-decoder models.

Also explained in

Compare how 6 books explain image segmentation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.