Sub topic 2
Defining Classes and a Label Taxonomy
Assume you know basic Python, JSON, image dimensions, and the idea of supervised learning. This chapter focuses on deciding what labels mean before annotators draw boxes or masks. A clear taxonomy makes labels consistent and makes model results easier to interpret.
What a class means
A class is a named category that an annotation can belong to, such as car, pedestrian, or traffic_light. A label taxonomy is the complete structure of classes, attributes, and special cases used in a dataset.
Start with the model's intended decision. If the model only needs to count vehicles, car, truck, and bus may be useful classes. If it must control a vehicle safely, separating car, truck, bus, motorcycle, and bicycle may be necessary.
Choose classes that are:
- Relevant to the product or research question.
- Visible often enough to provide useful training examples.
- Distinguishable from one another in the images.
- Defined at a consistent level of detail.
- Stable across annotators and future data collection.
Avoid mixing levels of detail. A taxonomy containing vehicle, car, and sedan is ambiguous unless it explicitly defines whether one object can receive all three labels.
Flat classes and hierarchies
A flat taxonomy gives each object one class from a single list. For example:
cartruckbusmotorcycle
A hierarchical taxonomy represents broader and narrower categories. A sedan could belong to vehicle > car > sedan. Hierarchies are useful when different applications need different levels of detail, but they require more rules and more complex evaluation.
For most first datasets, use a flat taxonomy unless the hierarchy supports a specific requirement. You can store optional attributes separately instead of creating many small classes.
| Decision | Example | Use when |
|---|---|---|
| Separate class | `car` and `truck` | The model must distinguish them |
| Attribute | `car` with `color: red` | Color varies independently of object identity |
| Ignore region | Reflections or unreadable signs | The content should not affect training |
| Unknown class | Unclear vehicle type | The object matters, but its class cannot be identified |
Write class definitions
Each class needs a short definition, positive examples, exclusions, and edge-case rules. For example:
car: A road vehicle designed mainly to carry people, including sedans, hatchbacks, wagons, and convertibles.- Exclude vans, buses, and motorcycles.
- Include a car when at least part of its body is visible.
- Keep the class
carwhen its color, brand, or model is unknown.
Define whether labels describe the object itself or its visible appearance. A partially hidden car is still a car. Occlusion should usually be recorded as an attribute rather than creating a class such as partly_hidden_car.
Use an ignore or unknown policy deliberately. unknown means the object is relevant but cannot be assigned confidently. ignore means the region should not count as either a positive or negative example. Do not silently convert uncertainty into a random class.
Separate identity from attributes
Classes should capture the main object category. Attributes capture properties that do not change that category.
Useful attributes may include:
occluded: none, partial, or heavy.truncated: none, partial, or fully cut off by the image edge.visible: yes or no.crowd: whether several objects cannot be separated reliably.quality: clear, blurry, or ambiguous.
This design prevents class explosion. For example, use car plus occluded: partial, rather than separate classes for visible_car and occluded_car.
A taxonomy should also define whether multiple labels are allowed for one object. In a mutually exclusive taxonomy, an object receives exactly one class. In a multi-label taxonomy, an object may receive several independent labels, such as vehicle and emergency_vehicle. Choose one approach and document it.
CLASS_RULES = {
"car": {
"definition": "Passenger road vehicle",
"excludes": {"truck", "bus", "motorcycle"},
},
"truck": {
"definition": "Goods-carrying road vehicle",
"excludes": {"car", "bus", "motorcycle"},
},
}
def validate_class(name):
if name not in CLASS_RULES:
raise ValueError(f"Unknown class: {name}")
if not CLASS_RULES[name]["definition"]:
raise ValueError(f"Missing definition for {name}")
for class_name in CLASS_RULES:
validate_class(class_name)
print("Taxonomy is valid:", ", ".join(CLASS_RULES))Test the taxonomy before scaling
Pilot the taxonomy on a small, varied sample. Have at least two annotators label the same images independently. Compare disagreements and revise definitions that produce repeated uncertainty.
Check especially:
- Similar classes, such as van versus truck.
- Tiny or blurry objects.
- Objects cut by image boundaries.
- Reflections, posters, screens, and photographs of objects.
- Groups where individual instances cannot be separated.
- Rare classes with too few examples.
Freeze the class names and identifiers before training. Renaming or reordering classes later can invalidate annotations and model configuration. Keep a versioned taxonomy document so every annotation can be traced to the rules used at the time.
Exercise
You need to detect road vehicles, but annotators often confuse vans and trucks. Should you immediately create more classes?
Show answer
No. First define observable criteria and test them on a pilot set. Add separate classes only if the distinction is required, visible in the images, and consistent between annotators.