Sub topic 3
Writing labelling guidelines for occlusion, truncation and ambiguity
This chapter assumes you know the task types (detection, instance segmentation) and have a class taxonomy with written definitions. You should also be comfortable with bounding boxes in pixel coordinates and with basic Python dictionaries. The chapter covers the rules that decide what an annotator draws when an object is hard to see, cut off by the frame, or hard to name.
Why guidelines matter more than tools
Two annotators looking at the same image will disagree. Most of the disagreement comes from unwritten decisions, not from carelessness. Does a car half hidden behind a bus count? Should the box include the hidden half? What do you do with a blurry shape that could be a pedestrian or a signpost?
A model trained on inconsistent answers learns the inconsistency. If one annotator boxes only the visible part of occluded objects and another boxes the full inferred extent, the model sees the same situation with two different targets. It will output boxes that sit between the two, and your IoU against either style will suffer.
A labelling guideline is a written document that turns these decisions into rules that any trained annotator applies the same way. A good guideline is short enough to be read, specific enough to be tested, and illustrated with example images.
The guideline sits on top of the class taxonomy. The taxonomy says what the classes are. The guideline says when an instance of a class is labelled, how it is drawn, and what happens in the grey areas.
The three problem cases
Almost every edge case falls into one of three groups.
| Problem | What happens | Typical question |
|---|---|---|
| Occlusion | Another object or surface hides part of the target | Box the visible part or the full extent? |
| Truncation | The image border cuts off the target | Box to the border, or estimate beyond it? |
| Ambiguity | The class, the instance boundary, or the very existence of the object is unclear | Label it, skip it, or flag it? |
Occlusion and truncation both mean you cannot see all of the object. They differ in cause, and the same rule does not always suit both. The next sections take each in turn.
Occlusion rules
The first decision is what the box represents. There are two common conventions.
- Visible extent (modal). The box or polygon covers only the pixels you can see.
- Full extent (amodal). The box covers the whole object, including the hidden part, as estimated by the annotator.
Choose one per project and state it at the top of the guideline.
| Convention | Strength | Weakness |
|---|---|---|
| Visible extent | Objective. Annotators can verify each edge against pixels. | Boxes of the same object change as it moves behind things. Overlapping boxes are less useful for tracking. |
| Full extent | Gives a stable object size, which helps counting and tracking. | Hidden edges are guesses, so agreement between annotators is lower. |
For segmentation masks, visible extent is almost always the right choice. A mask claims that those pixels belong to the object, and hidden pixels have no evidence. For boxes, either convention can work, but visible extent gives higher inter-annotator agreement and is the safer default unless a downstream use needs full extent.
The second decision is a threshold: how much of the object must be visible before you label it? Without a number, every annotator picks a different cut-off. Write a rule such as:
- Label an object if at least 20% of it is visible, or if its class can be identified with confidence from the visible part.
- Do not label an object whose visible part is smaller than 10 by 10 pixels.
- If an object falls below the threshold, leave it unlabelled and do not mark it as anything else.
The percentages are illustrative. Pick values that match what your model needs to detect, and check them on a sample of real images. The percentage is hard to judge by eye, so back it up with a practical test, for example "if you can tell what it is without guessing, label it".
Layered and crowded scenes
Crowds create their own problems. In a dense group of people, you may see only a head and a shoulder for each person. Decide in advance between these options:
- Label every identifiable individual, including those with small visible parts.
- Label individuals above the threshold and mark the rest as a single crowd region.
- Skip the heavily overlapped ones.
COCO has a field for the second option. An annotation with iscrowd set to 1 marks a region containing many instances that cannot be separated, and standard evaluation code treats it differently: predictions that fall in a crowd region are not counted as false positives. If your evaluation uses COCO tooling, use this field instead of inventing your own marker.
Truncation rules
Truncation means the image frame cuts the object off. The object is complete in the world, but the picture shows only part of it.
The usual rule is to box only what is inside the image, and let the box edge touch the image edge. This keeps the box inside valid coordinates. The validation check from this tutorial flags any box that extends beyond the image, so a rule that asks annotators to estimate beyond the border would fail that check by design.
Add the following to the guideline:
- A truncated object is labelled if the visible part meets the same visibility threshold as for occlusion.
- The box edge sits exactly on the image border on the cut side. Annotators should not leave a gap of a few pixels.
- If the dataset format supports a truncation flag, set it. Pascal VOC has a
truncatedfield per object, and adifficultfield for objects that are hard to recognise.
A truncation flag costs little to record and helps later. When you do error analysis, you can check whether the model fails mostly on truncated objects, and you can filter them out of an evaluation when comparing two models.
Truncation versus occlusion at the border
Sometimes an object is both truncated and occluded, for instance a car cut off by the frame and partly behind a tree. Say in the guideline that each effect is handled by its own rule. The box covers the visible pixels, it stops at the border, and the object must still pass the visibility threshold as a whole.
Ambiguity rules
Ambiguity comes in several kinds, and each needs a different instruction.
Class ambiguity
The object is clearly there, but the class is uncertain. A person on a motorbike might belong to person, motorcyclist or motorbike. A van might be a car or a truck.
Resolve these in the taxonomy where possible, with a decision rule rather than a description. For example: "A vehicle with a cargo area separate from the cab and a gross weight above 3.5 tonnes is a truck. Everything else on four wheels is a car." For the rest, add a fallback:
- A rule for choosing between two named classes, such as "choose the more specific class".
- A catch-all class such as
other_vehicle, used sparingly and reviewed regularly. - A way to flag the object for a reviewer instead of guessing.
Instance ambiguity
Several things touch, and it is unclear how many objects there are. Examples are parked cars bumper to bumper, a bunch of bananas, or a stack of chairs. Give a counting rule: "Separate instances are objects that could be moved independently. Label each one. If you cannot see a boundary between them, label the group as one iscrowd region."
Boundary ambiguity
Where does the object end? Shadows, reflections, motion blur, antennas, side mirrors, and the soft edges of fur all matter. A rule should say what is in and what is out:
- Include parts physically attached to the object, such as mirrors, handles and wing flaps.
- Exclude shadows, reflections and held items that are separate objects.
- Boxes are tight: each edge touches the outermost labelled pixel, with no padding.
Tightness is worth stating explicitly. A box that is five pixels loose on each side will still match another annotator's tight box at a high IoU for a large object, but for a small object of 20 pixels it will drop the IoU a lot.
Existence ambiguity
The thing might not be there at all: a reflection in a window, a poster showing a person, a statue, a toy car. The guideline must say whether these count. A reflection of a car in a shop window is not a car for a driving-detection model, but a statue of a person may count as person for a model that is used to count visitors in a gallery. The answer depends on the use of the model, so state it and give an image of each case.
Making rules testable
A rule is only useful if two annotators following it reach the same result. Review each rule against three questions:
- Can it be applied from the image alone, without knowing the annotator's intent?
- Does it give a number or a yes/no test in place of words such as "mostly", "clearly" or "significant"?
- Does it have an example image showing a case that is labelled and one that is not?
Rules that fail these tests tend to produce low agreement when you measure it. A later chapter covers measuring agreement with IoU; the link to this chapter is that low agreement usually points to a guideline gap, not to a careless annotator.
Here is a compact guideline excerpt for a street-scene detection project, to show the level of detail to aim for:
Recording flags instead of losing information
Some decisions are better stored than enforced. If annotators set attributes such as occluded, truncated and uncertain on each object, you keep the information, and you can decide later how to use it. The cost is a few clicks per object, so keep the list of attributes short.
COCO does not define these attributes in its core schema, but extra keys in an annotation are usually preserved by tools and ignored by standard evaluation code. A custom field like the one below is a common pattern.
{
"id": 7,
"image_id": 1,
"category_id": 1,
"bbox": [600, 40, 40, 50],
"area": 2000,
"iscrowd": 0,
"attributes": {"occluded": false, "truncated": true, "uncertain": false}
}Check that your conversion scripts and your training code do not drop or choke on the extra key before you rely on it.
You can also use the flags in a validation script. This function reports annotations that are marked truncated but do not touch an image border, which is a sign that the flag or the box is wrong.
def check_truncation_flag(ann, img_w, img_h, tol=1):
x, y, w, h = ann["bbox"]
touches_border = (
x <= tol
or y <= tol
or x + w >= img_w - tol
or y + h >= img_h - tol
)
flagged = ann.get("attributes", {}).get("truncated", False)
problems = []
if flagged and not touches_border:
problems.append("flagged truncated but box does not touch the border")
if touches_border and not flagged:
problems.append("box touches the border but is not flagged truncated")
return problems
ann = {
"bbox": [600, 40, 40, 50],
"attributes": {"occluded": False, "truncated": True},
}
print(check_truncation_flag(ann, 640, 480))For the sample annotation, the box ends at x = 640, which is the image width, so the function prints an empty list.
Keeping the guideline alive
A guideline changes. Annotators will find cases you did not predict, and you should expect to revise it in the first weeks.
- Keep a version number and a short change log. When a rule changes, note the date, so you know which labels were made under which rule.
- Keep a running list of questions from annotators. Each repeated question is a missing rule.
- Add the resolved edge cases as images with a one-line decision.
- When a rule changes in a way that affects past labels, decide whether to relabel. A cheap script can often find the affected annotations, such as all boxes under a size threshold or all objects with a given flag.
- Run a short calibration round whenever a new annotator joins or the guideline changes: everyone labels the same 20 to 50 images, and you compare results and discuss the differences.
Common mistakes
- No stated box convention. The visible versus full extent choice is left open, and half the dataset follows each.
- Vague thresholds. "Label if mostly visible" means something different to each person.
- Guessing the class. Annotators who must always pick a class will choose one at random on hard cases. Offer a review flag.
- Labelling the same thing differently across images. The same object type is handled one way in daytime photographs and another at night. Include examples for each condition.
- Too many rules. A 40-page guideline is not read. Put the ten most common cases on the first page and the rest in an appendix.
- Ignoring the downstream use. Rules should come from what the model must do, such as detect partly hidden pedestrians for safety, and not from what is easy to draw.
Summary of decisions to write down
The diagram shows the order in which an annotator applies the rules to a single candidate object.
Exercise
A project uses visible-extent boxes with a rule to label objects that are at least 20% visible. An annotator sees a bus whose rear third is cut off by the right edge of the image, and a bicycle behind a parked van with only the front wheel showing. How should each be handled, and which flags should be set?
Show answer
The bus passes the visibility threshold because about two thirds of it is visible. Draw a tight box around the visible part, let the right edge of the box sit exactly on the image border, and set truncated. The bicycle depends on the numbers. A front wheel alone is probably far below 20% of the bicycle, so unless the guideline's "class clearly identifiable" test is met, it is left unlabelled. If a wheel is judged enough to identify a bicycle and the guideline allows it, draw a box around only the visible wheel, set occluded, and flag it for review. In both cases the box covers visible pixels only.
Exercise
Write the check that would flag a COCO box in [x, y, w, h] format that is marked truncated but sits well inside the image. Use a tolerance of 1 pixel. Then say what the function returns for the box [100, 100, 50, 50] with the truncated flag set, in a 640 by 480 image.
Show answer
Use the function checktruncationflag from this chapter. It tests whether x <= 1, y <= 1, x + w >= imgw - 1 or y + h >= imgh - 1. For [100, 100, 50, 50] none of these hold, because the right edge is at 150 and the bottom edge at 150, so touches_border is False. Because the flag is set, the function returns ["flagged truncated but box does not touch the border"].