Overlapping silver and cyan wire rectangles surrounding a metal workpiece.

What you need

Use simple axis-aligned boxes with a documented coordinate convention. Test the metric independently of your model.

IoU for horizontally shifted 100-pixel boxes. 0-pixel shift: 1 ratio; 20-pixel shift: 0.667 ratio; 50-pixel shift: 0.333 ratio.
IoU for horizontally shifted 100-pixel boxes. Original Academy diagram using illustrative values; not a measured hardware result.
Read the diagram as a data table
Values used in the illustration
Condition or componentratio
0-pixel shift1
20-pixel shift0.667
50-pixel shift0.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

Illustrative numbers. Replace them with your measured inputs.

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

  1. Confirm whether box edges are continuous coordinates or inclusive integer indices; use one convention consistently.
  2. Calculate overlap for identical, disjoint and partially overlapping boxes and verify the expected results.
  3. Choose and report a matching threshold appropriate to the evaluation, and prevent duplicate predictions from matching the same object.
  4. 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.

Read our methods, limitations and safety notes.