liveBook · Manning

Chapter 11: Image segmentation

What you will learn in chapter 11 of Deep Learning with Python, Third Edition

The introduction positions image segmentation as another computer vision application beyond image classification and previews the chapter’s topics.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction positions image segmentation as another computer vision application beyond image classification and previews the chapter’s topics.

11.1 Computer vision tasks

The section distinguishes image classification, image segmentation, and object detection by what each produces from an image.

Key terms: image classification, image segmentation, object detection, bounding boxes, single-label classification, multilabel classification, mutually exclusive

11.1.1 Types of image segmentation

The section defines image segmentation as pixel-level labeling and distinguishes semantic, instance, and panoptic segmentation.

Key terms: image segmentation, pixel, class, semantic segmentation, instance segmentation, panoptic segmentation, semantic label, instance label

11.2 Training a segmentation model from scratch

Introduces a forthcoming semantic segmentation example using cat and dog images to distinguish the main subject from its background.

11.2.1 Downloading a segmentation dataset

This section introduces the Oxford-IIIT Pets segmentation dataset, explains its pixel-level masks, and prepares paired inputs and targets for training.

Key terms: segmentation mask, foreground, background, contour, Oxford-IIIT Pets dataset, images/, annotations/trimaps/, NumPy arrays, training, validation

11.2.2 Building and training the segmentation model

The section explains how a segmentation model compresses an image, upsamples features into a per-pixel mask, and evaluates the result.

Key terms: Conv2D, feature maps, downsample, strides, max pooling, location information, per-pixel target masks, Conv2DTranspose, upsample, num_classes

11.3 Using a pretrained segmentation model

This section explains why a pretrained model is useful for image segmentation and introduces SAM’s ability to segment objects without a fixed class list or fine-tuning.

Key terms: pretrained model, Segment Anything Model, segmentation masks, SAM, predefined set of object classes, fine-tune

11.3.1 Downloading the Segment Anything Model

This section shows how to obtain a pretrained Segment Anything Model through KerasHub’s ImageSegmenter task and identifies the chosen preset.

Key terms: KerasHub, ImageSegmenter, SAM, sam_huge_sa1b, SA-1B, 641 million parameters

11.3.2 How Segment Anything works

This section explains how Segment Anything’s segmentation data, prompted training examples, and model components work together to predict object masks.

Key terms: SA-1B, segmentation mask, semiautomated, (image, prompt, mask) triples, point prompt, box prompt, ground truth mask, image encoder, image embedding, prompt encoder

11.3.3 Preparing a test image

The section prepares a test image for SAM without distorting it and introduces utilities for displaying segmentation results.

Key terms: SAM, aspect ratio, pad_to_aspect_ratio, keras.ops.image.resize(), Matplotlib axis object, ax, segmentation masks

11.3.4 Prompting the model with a target point

The section shows how to prompt SAM with labeled points and interpret its alternative segmentation masks.

Key terms: SAM, point prompt, foreground, background, masks, candidate masks, iou_pred, ambiguous prompts

11.3.5 Prompting the model with a target box

This section shows how to prompt SAM with a box around an object and notes its use for creating segmentation-mask datasets.

Key terms: target points, boxes, top-left and bottom-right corners, SAM, segmentation masks

11.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 10: Interpreting what ConvNets learn Chapter 12: Object detection →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.