PIoU Loss: Towards Accurate Oriented Object Detection in Complex Environments
- Publication
- ECCV 2020Conference
- First submitted to arXiv
- arXiv:2007.09584
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{retailproductpiou2020,
title = {{PIoU Loss: Towards Accurate Oriented Object Detection in Complex Environments}},
author = {Zhiming Chen and Kean Chen and Weiyao Lin and John See and Hui Yu and Yan Ke and Cong Yang},
year = {2020},
eprint = {2007.09584},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2007.09584}
}
Every level of a store shelf has a long, narrow shelf edge at the front, lined with price tags.
If you want to know how many levels a shelf photo contains and where each one starts and ends, the most direct approach is to box the edge of every shelf. These boxes are long and thin, with aspect ratios of 1 to 20 being nothing unusual; tilt the photo a little and the boxes tilt with it.
This paper comes from Clobotics, a retail AI company, and Shanghai Jiao Tong University. The authors found that rotated-box detectors trained the usual way at the time were especially inaccurate on long, thin objects like these, so they proposed a new loss function, PIoU Loss, and along the way released Retail50K, a dataset that targets shelf edges specifically.
Problem Definition
An oriented bounding box (OBB) is described by five numbers: the center , the width and height , and the angle . Most rotated-box detectors at the time added an angle dimension to a horizontal-box detector and then regressed each of the five numbers separately with a distance loss such as L1 or SmoothL1.
The problem is that distance losses are only loosely tied to IoU.

This figure makes the problem very clear. The two pairs of boxes have exactly the same SmoothL1 loss, 0.57, yet one has an IoU of 0.35 and the other 0.72.
The cause is the aspect ratio. For a very long box, a slight angle error swings the two ends farthest from the center way off, and IoU falls fast; but to SmoothL1, an angle error is just a number, and it doesn't care how long the box is. The thinner the box, the worse this mismatch gets.
So why not just use IoU as the loss? IoU losses for horizontal boxes (like GIoU) already existed, but the intersection of two rotated boxes can be an arbitrary polygon with up to eight sides, and writing a differentiable formula for it is a pain.
Solution
The authors' idea is down to earth. If the shape of the intersection is hard to compute, don't compute the shape; count it pixel by pixel instead.
First, Is the Pixel Inside the Box?

Given a rotated box and a pixel , deciding whether is in the box only takes projecting the vector from to the box center onto the box's width and height directions.
Let the distance from to the center be and the angle between this vector and the box's width direction be ; then the distance along the width is and the distance along the height is . is determined by the box angle together with the pixel's bearing.
A pixel is inside the box when it doesn't go past half the side length in either direction:
With this test, the intersection is the number of pixels both boxes call "inside", the union is the number of pixels at least one box calls "inside", and dividing one by the other gives IoU. The authors count pixels only within the smallest horizontal rectangle that covers both boxes, so there's no need to scan the whole image.
Making It Differentiable
The above is a step function that jumps straight from 1 to 0 at the box boundary, with no gradient to pass back. The authors replace it with a sigmoid-shaped kernel:
is the position of the boundary and controls how steep the curve is. Each pixel's contribution is the product of the kernels in the width and height directions, .
The paper's formula writes as the full side lengths and ; the official code actually uses half the side length, factor = -k * (dis_w - w / 2.), which matches the inside-the-box condition above.
Let's plug in a box. Say it's 40 pixels wide, so the half-width is 20, and :
- A pixel 19 pixels from the center along the width, still inside the box, gets .
- Exactly on the boundary, at 20 pixels, .
- 0.3 pixels outside, at 20.3 pixels, .
So with , apart from a band less than a pixel wide around the boundary, the kernel is essentially 0 or 1 everywhere. Its job is to give the pixels on the boundary a gradient, telling the network "push the box a little this way and you'll cover a few more pixels".
Most pixels inside the box have values close to 1, with fixed contributions and tiny gradients; the ring of pixels near the boundary is where the gradient comes from, and the positions of these pixels depend on all five parameters at once (center, width/height and angle). That's why PIoU can optimize the five parameters jointly.
The intersection and the union are both replaced by sums of kernels:
The union can be simplified one step further, as the areas of the two boxes minus the intersection, . The authors call this simplified version HPIoU.
The Loss
, and the loss takes its negative log, averaged over all positive pairs:
is the set of positive pairs, which require an IoU above 0.5 between the anchor box and the annotated box. Since the kernel isn't truly 0 outside the box, PIoU stays above 0 even when two boxes don't intersect at all, so the gradient is still there. Set to 0 and the loss works for horizontal boxes too.
The authors plug PIoU into two detectors, the anchor-based RefineDet and the anchor-free CenterNet; in both, the original box regression loss is replaced with PIoU and the classification loss is left alone. CenterNet's center points are decided by the heatmap, so PIoU's gradient isn't passed back to the center point.
Retail50K

With Retail in the name, it's easy to assume it's a product dataset. In fact, Retail50K doesn't annotate products; it annotates the edge of every level of shelves, freezers and display racks, and the whole dataset has just this one class.
The authors give three reasons. Shelf edges are blocked by price tags and promotional labels, with an average occlusion of about 37.5%, against a background of brightly colored products; the box aspect ratios are extreme, with a median of 1 to 20, while 90% of the boxes in the aerial datasets commonly used at the time are within 1 to 4; and in practical applications, finding the shelf edges lets you split a shelf into levels, detect price tags, and estimate the camera's skew angle.
The data was shot by dozens of volunteers on their own phones in 20 supermarkets in China and the US, 47,000 images in total, all resized to 600×800. Annotation used arbitrary quadrilaterals first, which were then converted into rotated boxes. The training, validation and test split is 1/2, 1/6 and 1/3.
Discussion
Results on Retail50K
| Detector | Backbone | Base AP | + PIoU | AP50 change | AP75 change |
|---|---|---|---|---|---|
| RefineDet-OBB | ResNet-50 | 53.96 | 61.78 | 74.15 → 80.17 | 33.77 → 43.39 |
| RefineDet-OBB | ResNet-101 | 55.46 | 63.00 | 77.05 → 79.08 | 33.87 → 46.01 |
| CenterNet-OBB | ResNet-18 | 54.44 | 61.02 | 76.58 → 87.19 | 32.29 → 34.85 |
| CenterNet-OBB | DLA-34 | 56.13 | 61.64 | 78.29 → 88.47 | 33.97 → 34.80 |
Source: Table 5 of the paper; AP is averaged over IoU from 0.5 to 0.95.
All four settings improve by 5.5 to 7.8 points. The loss is only used in training, so inference speed is exactly the same; CenterNet with ResNet-18 runs at 140 images per second.
Look closely at the last two columns and the two detectors improve in different ways. RefineDet gains mainly in AP75, meaning its boxes fit more tightly; CenterNet gains mainly in AP50, with AP75 up only 0.8 to 2.6 points. On the CenterNet side, PIoU's gradient isn't passed back to the center point, so the box position is set by the heatmap and PIoU can only adjust width, height and angle, which may be why its improvement at the strict threshold is limited. The paper doesn't discuss this difference.
Against Other Losses
On aerial DOTA, the authors keep RefineDet fixed and swap only the loss:
| Loss | AP | AP50 | AP75 | Train (h) |
|---|---|---|---|---|
| L1 | 50.66 | 64.14 | 37.18 | 20 |
| L2 | 49.70 | 62.74 | 36.65 | 20 |
| SmoothL1 | 51.46 | 65.68 | 37.25 | 21.5 |
| PIoU | 54.24 | 67.89 | 40.59 | 25.7 |
| HPIoU | 53.37 | 66.38 | 40.36 | 24.8 |
Source: Table 3 of the paper.
PIoU beats SmoothL1 by 2.8 points, at the cost of about 20% more training time. The simplified HPIoU saves some computation and scores only 0.9 lower.
The choice of matters quite a bit too. With , AP is only 46.88; gives 54.24, and gives 53.41. A reasonable explanation is that when is too small, the kernel blurs the line between inside and outside the box, and the computed IoU drifts from the true value; when it's too large, the kernel approaches a step function, and the gradient concentrates on too narrow a ring of pixels. The paper only reports the numbers and doesn't analyze the cause.
On the DOTA test set, PIoU improves each of three settings by 1.4 to 1.6 points, much less than the 5.5 to 7.8 points on Retail50K. The authors see this as evidence that PIoU is especially effective on high-aspect-ratio objects; the DOTA classes that benefit more are also long, thin targets such as harbors, ground track fields and soccer fields.
It works for horizontal boxes too. With SSD on PASCAL VOC, SmoothL1 gets 48.8, GIoU 49.9 and PIoU 50.3.
Can You Get Retail50K?
The paper says the dataset will be made public on GitHub. The repo does have Retail50K, in the form of a few CSV files where each row is an image URL plus annotation coordinates, and you have to download the images one by one yourself.
The rest of the story is in the issues. In August 2020, someone parsed the CSVs and found only 40,063 images across training and test, not the 47,000 the paper states; the paper mentions a validation set, but the CSVs have none; the two training CSVs share 2,987 duplicate images; and plotting the boxes revealed quite a few missing and wrong labels (issue #6). In 2023 someone else reported missing labels, such as an entire bottom row of price tags left unannotated in one image (issue #20); the same year, someone said the server reset the connection halfway through the download (issue #19).
None of these issues got a single reply from a maintainer. The repo's last update was on July 21, 2020, two days after the paper went up on arXiv (paper's out, shift's over). We tried the URL of the image posted in issue #6; connecting in November 2026, it redirects to a 404.
Somewhat ironically, in the issues of the previous paper, DRN, someone complained that DRN was only half open-sourced, and the suggestion underneath was "use PIoU, I've already reproduced it". PIoU's loss function code is indeed complete, with both CPU and CUDA versions; the dataset wasn't so lucky.
Conclusion
The problem PIoU solves is well defined. Distance losses don't care how long a box is; IoU does. With per-pixel accumulation and a sigmoid kernel, the authors sidestep the hassle of rotated-box intersections being arbitrary polygons, so IoU can be used directly as a loss and pass back gradients. The experiments also back the claim that "the thinner the box, the more it helps": 5.5 to 7.8 points of improvement on Retail50K, with its median aspect ratio of 1 to 20, versus only about 1.5 points on DOTA.
Long, thin targets that rotate, such as shelf edges, price-tag strips and text lines, are all good candidates for trying PIoU. It adds no cost at inference and about 20% more training time. If you implement it yourself, go by the official code and use half the side length for the kernel boundary; if you use HPIoU's simplified union but compute the intersection with the full side length as in the paper's formula, the areas on the two sides won't match.
As for Retail50K, before using it as a benchmark, you'd do well to count how many images you can actually download.