
What you need
Use simple axis-aligned boxes with a documented coordinate convention. Test the metric independently of your model.
Read the diagram as a data table
| Condition or component | ratio |
|---|---|
| 0-pixel shift | 1 |
| 20-pixel shift | 0.667 |
| 50-pixel shift | 0.333 |
The calculation
IoU = A_intersection / (A_predicted + A_reference − A_intersection)
Areas use square pixels. Clamp negative intersection widths and heights to zero and handle degenerate zero-area boxes.
Worked example
Two 100×100 boxes shifted 20 pixels horizontally overlap over 80×100 = 8,000 pixels². Their union is 12,000 pixels², giving IoU = 0.667. A 50-pixel shift gives IoU = 0.333.
Try it step by step
- Confirm whether box edges are continuous coordinates or inclusive integer indices; use one convention consistently.
- Calculate overlap for identical, disjoint and partially overlapping boxes and verify the expected results.
- Choose and report a matching threshold appropriate to the evaluation, and prevent duplicate predictions from matching the same object.
- Evaluate grasp-point position separately, especially where a large box can have acceptable overlap despite an unusable target.
How to check the result
The implementation should return 1 for identical nondegenerate boxes and 0 for disjoint boxes, with no negative areas.
Common mistake to avoid
The same pixel shift has a different IoU for large and small objects. Comparing IoU without object-size context can conceal localization weaknesses.
Reference reading
Primary references for the underlying models, APIs or application context. The worked numbers and plots above are educational calculations, not results reported by these sources.


