Sub topic 1
What you are labelling: detection and segmentation task types
Prerequisites
This chapter assumes you know basic Python, JSON, and the idea that an image is a pixel array with a width and height. You should also understand that supervised learning trains a model from examples containing inputs and target labels.
An annotation is a recorded description of something visible in an image. The correct annotation depends on the model task. A class label alone cannot answer where an object is, and a bounding box cannot describe its exact outline.
The five common task types
Image classification
Image classification assigns one or more labels to the whole image. It answers, “What is present in this image?” It does not identify the location of an object.
For example, an image might receive the label street_scene. If several labels are allowed, the same image could receive street_scene, rainy, and night.
Classification is suitable when the image-level category is enough for the application. It is not suitable when the model must count objects or locate them.
Object detection
Object detection assigns a class and a bounding box to each object. A bounding box is usually stored as a rectangle around the object.
For an image containing two cars and one bicycle, the labels might be:
carwith box 1carwith box 2bicyclewith box 3
Detection provides object locations efficiently, but the box includes background pixels. It is often a good choice for counting, tracking, or triggering an action near an object.
Semantic segmentation
Semantic segmentation assigns a class to each relevant pixel. All pixels belonging to the same class share one label, even when they belong to different objects.
Suppose an image contains three cars. Semantic segmentation marks all car pixels as car. It does not distinguish car 1 from car 2. This works well when the important question is the area occupied by a material or region, such as road, sky, or vegetation.
Instance segmentation
Instance segmentation assigns a separate mask to every object instance. A mask is a set of pixels identifying the object's shape.
The three cars in the previous example become car_1, car_2, and car_3, each with its own mask. Instance segmentation is useful when objects touch or overlap and the application needs separate counts, measurements, or actions.
Panoptic segmentation
Panoptic segmentation combines semantic and instance segmentation. Every pixel receives a class, and every countable object also receives an instance identity.
A road pixel is labelled as road, while each car pixel is labelled both car and as belonging to a particular car instance. This gives complete scene coverage, but it requires more detailed annotations and more quality control.
| Task | Main label | Separates object instances? | Typical output |
|---|---|---|---|
| Classification | Whole-image class | No | `cat` |
| Detection | Class and box | Yes | `car` plus rectangle |
| Semantic segmentation | Class per pixel | No | Road mask |
| Instance segmentation | Class and mask | Yes | Separate mask per car |
| Panoptic segmentation | Class and instance per pixel | Yes | Complete scene map |
Choosing the task from the question
Start with the question the model must answer:
- “What kind of image is this?” Use classification.
- “Where are the objects?” Use detection.
- “Which pixels belong to this category?” Use semantic segmentation.
- “Which pixels belong to each individual object?” Use instance segmentation.
- “What covers every pixel, including separate objects?” Use panoptic segmentation.
The annotation effort increases as the required spatial detail increases. A classification label is quick to create. Polygon masks take longer and require clearer rules for boundaries, occlusion, and touching objects.
task_requirements = {
"whole_image": "classification",
"object_locations": "detection",
"class_regions": "semantic_segmentation",
"separate_object_shapes": "instance_segmentation",
"complete_scene_and_instances": "panoptic_segmentation",
}
question = "separate_object_shapes"
print(task_requirements[question])The output is instance_segmentation. This mapping is a planning aid, not a substitute for examining the deployment requirement.
How labels relate
Detection boxes and segmentation masks can describe the same object at different precision levels. A mask can produce a bounding box by taking the minimum and maximum x and y coordinates of its pixels. The reverse conversion is lossy: a box cannot recover the object's exact shape.
Exercise
Exercise
An image contains five people, and the application must count each person even when two people overlap. Which task should you annotate, and why?
Show answer
Use instance segmentation if the application needs each person's visible shape, or object detection if separate shapes are unnecessary. Semantic segmentation is insufficient because it merges all people into one class region.