Object Detection & Segmentation: An Overview

Deep Learning with Keras and TensorFlow 9 min min read Updated: Nov 16, 2026 Advanced
Object Detection & Segmentation: An Overview
Advanced Topic 9 of 9

More Than Classification

TaskOutputExample
ClassificationOne label for the whole imageThis is a dog
LocalizationLabel + one boxA dog is here
Object detectionMany labels + many boxesTwo dogs and a person, with positions
Semantic segmentationA class for every pixelRoad, car, sky, pedestrian regions
Instance segmentationPixel masks for each objectEach person outlined separately

Object Detection Basics

  • Bounding box: a rectangle given by (x, y, width, height)
  • Confidence: how sure the model is about the box
  • IoU (Intersection over Union): how much a predicted box overlaps the true box. 1.0 is perfect, 0 is no overlap
  • NMS (non-max suppression): removes duplicate boxes for the same object
  • mAP: the standard score for detection quality
python def iou(a, b): # boxes as (x1, y1, x2, y2) x1, y1 = max(a[0], b[0]), max(a[1], b[1]) x2, y2 = min(a[2], b[2]), min(a[3], b[3]) inter = max(0, x2 - x1) * max(0, y2 - y1) area_a = (a[2] - a[0]) * (a[3] - a[1]) area_b = (b[2] - b[0]) * (b[3] - b[1]) return inter / (area_a + area_b - inter) print(iou((0, 0, 10, 10), (5, 5, 15, 15))) # 0.1428...

Popular Detection Models

Model familyIdea
YOLOLooks at the image once, very fast, good for real time
SSDPredicts boxes at several scales, good for mobile
Faster R-CNNTwo stage, accurate but slower
KerasCV / KerasHub detectorsReady-made detection models for Keras
Practical advice: Training a detector from scratch needs a large labeled dataset. In practice you start with a pretrained detector and fine-tune it on your own images.

Segmentation and the U-Net Idea

A U-Net has an encoder that shrinks the image to learn what is in it, and a decoder that enlarges it back to the original size to say where it is. Skip connections copy detail from encoder to decoder.

python import keras from keras import layers inputs = keras.Input(shape=(128, 128, 3)) # Encoder c1 = layers.Conv2D(16, 3, padding="same", activation="relu")(inputs) p1 = layers.MaxPooling2D()(c1) c2 = layers.Conv2D(32, 3, padding="same", activation="relu")(p1) p2 = layers.MaxPooling2D()(c2) # Bottom b = layers.Conv2D(64, 3, padding="same", activation="relu")(p2) # Decoder with skip connections u1 = layers.UpSampling2D()(b) u1 = layers.Concatenate()([u1, c2]) d1 = layers.Conv2D(32, 3, padding="same", activation="relu")(u1) u2 = layers.UpSampling2D()(d1) u2 = layers.Concatenate()([u2, c1]) d2 = layers.Conv2D(16, 3, padding="same", activation="relu")(u2) outputs = layers.Conv2D(1, 1, activation="sigmoid")(d2) # one mask value per pixel model = keras.Model(inputs, outputs, name="mini_unet") model.compile(optimizer="adam", loss="binary_crossentropy") print(model.output_shape) # (None, 128, 128, 1)

The output has the same height and width as the input. Each pixel gets a probability, for example of belonging to the object.

Conclusion

Classification answers what is in the picture. Detection and segmentation answer where. For real projects, start from pretrained models and fine-tune.

Quick Summary: Detection finds boxes, segmentation labels pixels. U-Net shows the encoder-decoder idea with skip connections.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators