Sub topic 1
What you are labelling: detection and segmentation task types
Every labelling project starts with one decision: what kind of label will each image carry? The answer sets the tool you use, the time each image takes, the file format you store, and which models you can train. This chapter describes the five common task types, shows what each label looks like as data, and gives criteria for choosing between them.
Prerequisites
This chapter assumes you have the following:
- Basic Python, including lists, dictionaries and NumPy arrays.
- Familiarity with JSON files.
- Knowledge that an image is an array of pixels with a height and a width.
- A general idea of what training a supervised model means: the model learns from examples paired with correct answers.
You do not need to have trained a detector or used an annotation tool before.
The five task types
The tasks differ in how finely they locate things in the image. Each task below adds information to the one before it.
| Task | Question it answers | Label per image | Separates two objects of the same class? |
|---|---|---|---|
| Classification | What is in this image? | One class (or a set of classes) | No |
| Object detection | What is where, roughly? | A list of boxes, each with a class | Yes |
| Semantic segmentation | What class is each pixel? | One class ID per pixel | No |
| Instance segmentation | Which pixels belong to each object? | One mask per object, with a class | Yes |
| Panoptic segmentation | Both of the above for the whole image | One class and one segment ID per pixel | Yes, for countable objects |
Classification
A classification label describes the whole image. It may be single-label ("this photo is a street") or multi-label ("contains car, contains pedestrian"). It is the cheapest label to produce, and it carries no location. A multi-label classification set can tell you that a car is present. It cannot tell you where or how many.
Object detection
A detection label is a list of objects. Each object has a class and a bounding box, which is an axis-aligned rectangle that encloses the object. Boxes are cheap to draw, usually a few seconds each, and they separate individual objects. They are also coarse. A box around a diagonal bicycle contains mostly background, and boxes of neighbouring objects overlap.
Semantic segmentation
A semantic segmentation label is a mask the same size as the image. Each pixel holds a class ID. It describes shape precisely, but it has no notion of individual objects. If two cars touch, their pixels are all labelled "car", and the label cannot say where one car ends and the next begins.
Instance segmentation
An instance segmentation label gives each object its own mask, plus a class. Two touching cars get two masks. Masks of different objects may overlap in the annotation file, depending on the format. Instance segmentation usually ignores uncountable regions such as sky, road and grass.
Panoptic segmentation
Panoptic segmentation combines the previous two. Every pixel gets a class, and pixels that belong to countable objects also get an instance ID. This requires splitting classes into two kinds:
- Things are countable objects with clear boundaries, such as cars, people and dogs. Each thing gets its own segment.
- Stuff is amorphous regions you measure rather than count, such as road, sky and vegetation. All pixels of a stuff class form one segment.
Every pixel belongs to exactly one segment, so segments cannot overlap. That rule makes panoptic labels the most demanding to produce and to check.
What the labels look like as data
The following script builds a tiny 6 by 8 "image" with a road and two touching cars. It then derives each label type from the same underlying scene. The goal is to see that the task types differ in what they store, not in what they describe.
import numpy as np
H, W = 6, 8
ROAD, CAR = 1, 2 # class IDs; 0 is background
# Instance masks: 0 = no object, 1 and 2 = the two cars
instance = np.zeros((H, W), dtype=np.int32)
instance[1:4, 0:3] = 1
instance[1:4, 3:6] = 2 # touches car 1 at column 2/3
# Semantic mask: one class ID per pixel
semantic = np.zeros((H, W), dtype=np.uint8)
semantic[3:6, :] = ROAD
semantic[instance > 0] = CAR # cars drawn over the road
# Panoptic IDs: class * 1000 + instance (stuff has instance 0)
panoptic = semantic.astype(np.int32) * 1000 + instance
# Detection boxes in [x, y, width, height] derived from instance masks
boxes = []
for inst_id in (1, 2):
ys, xs = np.nonzero(instance == inst_id)
x, y = int(xs.min()), int(ys.min())
w, h = int(xs.max()) - x + 1, int(ys.max()) - y + 1
boxes.append({"class": "car", "bbox": [x, y, w, h]})
# Classification label: the set of classes present
classes_present = sorted({"road" if c == ROAD else "car"
for c in np.unique(semantic) if c != 0})
print("classification:", classes_present)
print("detection:", boxes)
print("semantic car pixels:", int((semantic == CAR).sum()))
print("instance IDs:", np.unique(instance).tolist())
print("panoptic segments:", np.unique(panoptic).tolist())The output shows several points:
- The detection boxes come out as
[0, 1, 3, 3]and[3, 1, 3, 3]. One mask per car gives one box per car. - The semantic mask has 18 car pixels, but nothing in it says there are two cars. That information exists only in
instance. - The panoptic IDs are
0,1000(road),2001(car 1) and2002(car 2). The ID encodes the class and the instance in a single number. Real formats use different encodings, but the principle is the same.
Notice the direction of derivation. You can derive boxes from instance masks, and a semantic mask from instance masks plus stuff regions. You cannot go the other way. If you label boxes, you cannot recover pixel boundaries later without relabelling. Detailed labels can always be reduced to coarser ones, so there is an argument for labelling at a finer level than you currently need. The cost is the main counterweight.
Choosing a task type
Pick the cheapest label that answers your product question. The factors below drive the decision.
- Does the application need location? If you only need to route or filter images, classification is enough.
- Does it need counts or per-object tracking? Detection or instance segmentation is needed. Semantic segmentation cannot count touching objects.
- Does it need shape or area? Measuring crop coverage, tumour size or the free space on a road needs pixel-accurate masks. Boxes overestimate area for irregular objects.
- Does it need the whole scene, including background regions? Driving scenes often need both lane surfaces (stuff) and vehicles (things). Panoptic labels fit that case.
- What is the labelling budget? Time per object grows quickly from classification to boxes to polygons. A typical order of magnitude is seconds for a box and tens of seconds to minutes for a careful polygon, depending on object complexity.
Common errors
Choosing the task by model fashion
Teams sometimes choose segmentation because a model supports it, then find the labelling budget cannot cover the dataset. A smaller detection dataset with consistent boxes often beats a small, inconsistent segmentation dataset. Choose from the product requirement, then check the budget.
Treating semantic labels as if they had instances
A semantic mask that is later "counted" by connected components merges touching objects into one blob. If you will ever need counts, label instances from the start.
Mixing things and stuff without a rule
If one annotator draws a separate mask for each tree and another paints "vegetation" as one region, the dataset has two incompatible definitions. Decide per class, in writing, whether it is a thing or stuff. The next chapters cover how to record this in a taxonomy.
Overlapping masks in a task that forbids them
Semantic and panoptic labels allow one class or segment per pixel. If annotators draw overlapping polygons, a tool exports whichever drawn last, silently. Check overlap rules before labelling begins.
Forgetting the background and "void" cases
Not every pixel has to carry a meaningful class. Many segmentation datasets reserve a "void" or "ignore" ID for pixels that annotators could not decide on, so the training loss can skip them. Without that ID, ambiguous pixels are forced into a real class and the model learns noise.
Losing the task type in the file
An annotation file does not usually declare whether it is semantic, instance or panoptic. A COCO file with segmentation fields is instance-style. A folder of PNG masks could be semantic or panoptic. Record the task type in the dataset documentation, so a later reader does not guess.
Summary
- Classification labels the image, detection labels boxes, semantic segmentation labels pixels by class, instance segmentation labels one mask per object, and panoptic segmentation covers every pixel with a class and, for things, an instance.
- Finer labels reduce to coarser ones, but coarser labels cannot be refined without new work.
- Pick the cheapest task type that answers the product question, confirm it against the budget with a pilot, and record the choice, including the things-versus-stuff split.
Exercise
A warehouse team wants to count pallets on a shelf, where pallets often touch each other, and does not need their exact outline. Which task type is the cheapest that works, and why would semantic segmentation fail?
Show answer
Object detection is the cheapest option that works. It gives one box per pallet, so the count is the number of boxes. Semantic segmentation labels every pallet pixel with the same class, so touching pallets merge into one region and the count cannot be recovered.
Exercise
In the script from this chapter, the panoptic ID is class * 1000 + instance. What values appear for the road and for the second car, and what is one limitation of this encoding?
Show answer
The road is 1000 (class 1, instance 0) and the second car is 2002 (class 2, instance 2). One limitation is that it supports at most 999 instances per class. A dataset with more instances per class in one image would collide with the next class's IDs.
Exercise
You have 2,000 images labelled with polygon instance masks. A colleague asks for bounding boxes for a detector. Can you provide them, and could you go the other direction if you only had boxes?
Show answer
Yes. Take the minimum and maximum x and y of each polygon (or mask) to get its box. The reverse is not possible, because a box does not record where inside the rectangle the object's pixels are, so masks would need relabelling.