Back to paper library
arXiv 2020CVPR 2020Retail visionPaper notes

DRN

Crooked Still Counts

Original paper

Dynamic Refinement Network for Oriented and Densely Packed Object Detection

Paper authors

Xingjia Pan · Yuqiang Ren · Kekai Sheng …

Show all 8 authors

Xingjia Pan · Yuqiang Ren · Kekai Sheng · Weiming Dong · Haolei Yuan · Xiaowei Guo · Chongyang Ma · Changsheng Xu

Publication
CVPR 2020Conference
First submitted to arXiv
arXiv:2005.09973
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{retailproductdrn2020,
  title = {{Dynamic Refinement Network for Oriented and Densely Packed Object Detection}},
  author = {Xingjia Pan and Yuqiang Ren and Kekai Sheng and Weiming Dong and Haolei Yuan and Xiaowei Guo and Chongyang Ma and Changsheng Xu},
  year = {2020},
  eprint = {2005.09973},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2005.09973}
}
On this page

SKU-110K turned the densely packed products on store shelves into a detection benchmark, with one horizontal box per product.

But people photographing shelves with a phone rarely hold it perfectly straight. Tilt the photo and the rows of products tilt with it, and the horizontal boxes start taking in a corner of the neighboring product. The tighter the products are packed, the worse the boxes overlap.

Aerial images have the same problem. Cars in a parking lot and ships in a harbor point every which way, and they're packed tightly. Tasks like these usually use rotated boxes, that is, rectangles with an extra angle parameter.

This paper comes from the Institute of Automation of the Chinese Academy of Sciences, Tencent Youtu and Kuaishou. The authors handle both kinds of scene together, and re-annotate SKU-110K with rotated boxes under the name SKU110K-R.

Problem Definition

The authors point out two problems.

The first is the receptive field. At every location, a convolution kernel looks at a square region aligned with the coordinate axes. Look at a long product lying at an angle through a square receptive field, and half of what you catch is background or neighbors.

The second is that the model is too "rigid". Once training is over, the parameters are fixed, and every test sample is judged with the same set of weights. In the authors' words, training goes from the particular to the general, while inference goes from the general back to the particular; atypical samples near the decision boundary are easy to get wrong when judged with general knowledge.

Methods for rotated objects at the time were mostly built on Faster R-CNN. Some generate horizontal proposals first and then classify them, but with tilted objects packed together, a horizontal proposal often crams several of them into one box; others use rotated anchors directly, with every combination of angle, scale and aspect ratio, and the number of anchors balloons.

The authors took another road, using the anchor-free CenterNet as the skeleton and adding two modules, one for each of the problems above.

Solution

Original Figure 2: the overall architecture of DRN. The input image passes through an Hourglass network, followed by the Feature selection module, and then splits into four output heads: angle, size, offset and the center heatmap. The size, offset and other regression heads are followed by Dynamic refinement for regression, and the heatmap by Dynamic refinement for classification.
Original Figure 2, Pan et al., from PDF page 3, arXiv license, scholarly quotation.

First, Teach CenterNet to Rotate

CenterNet treats each object as a point. The network outputs a heatmap whose peaks are object centers, and at those locations it regresses the object's width and height plus a small offset.

DRN adds an angle branch alongside, so each center point outputs seven numbers (cx,cy,h,w,θ,δx,δy)(c_x, c_y, h, w, \theta, \delta_x, \delta_y). The four corners of the box come from rotating (±w/2,±h/2)(\pm w/2, \pm h/2) by θ\theta with the rotation matrix MrM_r and then translating to the center point:

Plt=Mr[−w/2−h/2]+[cx+δxcy+δy]P_{lt} = M_r \begin{bmatrix} -w/2 \\ -h/2 \end{bmatrix} + \begin{bmatrix} c_x + \delta_x \\ c_y + \delta_y \end{bmatrix}

The other three corners follow the same pattern. The angle is regressed with an L1 loss and added to the width/height and offset losses, each with a weight of 0.1.

This is the paper's baseline. Both modules below are added on top of it.

Feature Selection Module

Original Figure 3: the top half is the feature selection module. The input feature X is first compressed into X_c, then split into three branches that use 3×3, 1×3 and 3×1 rotation convolution layers (RCL) to get X_1, X_2 and X_3; each branch computes its own attention map A_1, A_2, A_3, which are concatenated and passed through softmax, and an attention gate weights the three branches into the output Y. The angle θ is drawn from X and fed into every RCL. The bottom half is the rotation convolution layer: the angle θ is converted into offsets through a rotation matrix, turning the original square 3×3 grid of sampling points into a tilted diamond.
Original Figure 3, Pan et al., from PDF page 4, arXiv license, scholarly quotation.

The feature selection module (FSM) tackles the receptive field problem with two ideas, one for orientation and one for shape.

Orientation is handled by the rotation convolution layer (RCL), which borrows the mechanism of deformable convolution (DCN). DCN learns a set of offsets at every location so the kernel's sampling points can move off the original grid; RCL doesn't let the network learn the offsets freely, but first predicts an angle θ\theta and then computes the offsets from it:

δpi=Mr(θ)⋅pi−pi\delta p_i = M_r(\theta) \cdot p_i - p_i

pip_i are the original grid points of a 3×33 \times 3 kernel, from (−1,−1)(-1, -1) to (1,1)(1, 1). Let's take θ=30∘\theta = 30^\circ and work out two points.

Grid point (1,0)(1, 0), rotated by 30 degrees, lands at (cos⁡30∘,sin⁡30∘)≈(0.87,0.5)(\cos 30^\circ, \sin 30^\circ) \approx (0.87, 0.5), an offset of (−0.13,0.5)(-0.13, 0.5). Grid point (1,1)(1, 1) lands at (0.37,1.37)(0.37, 1.37), an offset of (−0.63,0.37)(-0.63, 0.37). Rotate all nine points this way and the square sampling grid turns 30 degrees as a whole, becoming the tilted diamond at the bottom of Figure 3.

So the difference between RCL and DCN is that the offsets aren't nine arbitrary vectors; they're tied together by a single angle and rotate as one.

Shape is handled by the branches. FSM splits the features into three branches, with 3×33 \times 3, 1×31 \times 3 and 3×13 \times 1 rotation convolutions. 1×31 \times 3 is a horizontal strip, suited to wide, flat objects; 3×13 \times 1 is a vertical strip, suited to tall, thin objects; once rotated, they fit wide or tall objects lying at an angle.

How are the three branches combined? Each branch goes through its own 1×11 \times 1 convolution to get an H×W×1H \times W \times 1 attention map AiA_i. The three maps are stacked, a softmax over the three branches is taken at every pixel to get the weights Ai′A_i', and the branches are summed with these weights:

Y=∑iAi′⋅XiY = \sum_i A_i' \cdot X_i

Each location decides for itself which branch to listen to. An upright bottle of shampoo will probably pick the tall, thin 3×13 \times 1; a box of cookies lying on its side will probably pick the wide, flat 1×31 \times 3.

Dynamic Refinement Heads

The second module deals with the model being "too rigid". It's called the dynamic refinement head (DRH), and it comes in a classification version and a regression version.

Take DRH-C, for classification, first. An ordinary classification head classifies directly from the feature FmidF_{mid}. DRH-C adds a dynamic filter generator GcG_c that looks at the input features, generates a set of convolution kernels KcK_c on the spot, and convolves them over FmidF_{mid} to produce a correction FΔF_\Delta:

Kc=Gc(Fin),FΔ=Fmid∗KcK_c = G_c(F_{in}), \qquad F_\Delta = F_{mid} * K_c

The correction works by first normalizing FΔF_\Delta along the channel dimension into a unit vector, as the "direction to adjust in", and then scaling the original feature up or down proportionally:

Hc=C((1+ε⋅FΔ/∥FΔ∥)⋅Fmid)H_c = C\big((1 + \varepsilon \cdot F_\Delta / \lVert F_\Delta \rVert) \cdot F_{mid}\big)

ε\varepsilon controls the size of the correction. Since the filters are generated from the input, every image and every location gets a different correction, and that's what "dynamic" means here.

DRH-R, for regression, is more direct. It first gets a prediction HbH_b from an ordinary regressor, then multiplies it by a factor between 0.9 and 1.1:

Hr=(1+ε⋅tanh⁡(HΔ))⋅Hb,ε=0.1H_r = (1 + \varepsilon \cdot \tanh(H_\Delta)) \cdot H_b, \qquad \varepsilon = 0.1

tanh⁡\tanh squeezes the correction into [−1,1][-1, 1], so a prediction is adjusted by at most ±10%. The authors say ε\varepsilon is there to keep overly large corrections from throwing the model off.

In the final version, DRH-R is used only for size regression.

SKU110K-R

The original SKU-110K has 11,762 shelf photos and 1.73 million products. The authors observe that most products tilt within ±15 degrees, which hardly counts as genuinely rotated data.

To make the data more varied, they rotated each image by −45, −30, −15, 15, 30 and 45 degrees, producing six new versions, and had people annotate the rotated boxes one by one.

Original Figure 6: two SKU110K-R examples. On the left, a shelf of toothpaste and toiletries, slightly tilted, with a green rotated box on every product; on the right, a shelf of bottled drinks, rotated further, with the black triangles of blank space left by the rotation visible in the four corners.
Original Figure 6, Pan et al., from PDF page 5, arXiv license, scholarly quotation.

In the four corners of the right-hand image you can see the black triangles filled in after rotation. So the "rotation" in SKU110K-R is mostly made in post-production: the whole photo turns at once, and the products in one image share roughly the same angle. Real shelves, where every product leans its own way, get only limited coverage in this dataset.

Discussion

The backbone is Hourglass-104; on SKU110K-R the input resolution is 768×768, with 25 epochs of training. Evaluation follows COCO, with mAP averaged over IoU from 0.5 to 0.95.

Results on Shelves

DatasetMethodmAPAP75AR300
SKU110KSKU-110K paper (RetinaNet + EM-Merger)49.255.655.4
SKU110KYOLOv355.476.856.2
SKU110KBaseline (CenterNet)55.862.862.5
SKU110KDRN56.964.063.5
SKU110K-RYOLOv3-Rotate49.151.158.2
SKU110K-RCenterNet† (+ center pooling, DCN)54.761.162.2
SKU110K-RBaseline (CenterNet + angle)54.460.661.6
SKU110K-RDRN55.963.163.3

Source: Table 4 of the paper, excerpt.

Start with horizontal boxes on SKU110K. DRN's 56.9 is 7.7 points above the 49.2 of the original SKU-110K paper, but break it down and the CenterNet baseline alone already gets 55.8. Switching to an anchor-free skeleton accounts for most of the progress, and DRN's two modules add another 1.1.

Rotated boxes on SKU110K-R tell the same story, with the baseline at 54.4 and DRN at 55.9, 1.5 more. Also, the authors' own reproduction of YOLOv3-Rotate gets only 49.1, and CenterNet-4point, which regresses the four corners directly, only 34.3. In a scene this crowded, describing a box by its center, width/height and angle seems far more stable than regressing four corners.

Aerial Images

The paper's main battlefield is actually aerial imagery. DOTA has 15 object classes, from planes, ships and cars to tennis courts; HRSC2016 is ships.

On the DOTA test set without test-time augmentation, the baseline gets 65.04 and DRN 70.70. With multi-scale and flipping, DRN reaches 73.23, slightly above SCRDet at the time (72.61 with multi-scale). On HRSC2016, DRN's mAP is 92.7, against 86.2 for RoI Transformer.

Ablations

The ablations are all run on the DOTA validation set, with the backbone swapped for the smaller Hourglass-52, reporting AP50 and AP75.

The FSM part has a very clean comparison. A single 3×33 \times 3 branch without rotation matches the baseline (63.3 vs 63.4); adding rotation convolution lifts it to 63.9. With all three branches, all rotated, it reaches 64.4. With all three branches but rotation convolution swapped for ordinary DCN, it's only 63.9. Tying the offsets to one angle works slightly better than letting the network learn offsets freely.

DRH-C makes the center-point predictions more accurate. Looking at the 300 highest-scoring points per image, accuracy rises from 0.21 to 0.27, recall from 0.89 to 0.95, and AP50 gains 0.7.

DRH-R mainly improves size regression, cutting the L1 error from 5.34 to 4.12; on angle and offset it barely helps. That also explains why the final version uses it only on the size head.

On cost, processing a 1024×1024 image on one V100 takes 0.078 seconds for the baseline and 0.102 seconds with all three components added, with only about 0.16M extra parameters, and AP50 goes from 63.4 to 65.7.

The gains in these ablations are all small, each around 1 point, and every one of them was measured on DOTA; none were broken down on SKU110K-R.

How Open Is the Source?

The last sentence of the abstract says "The code and dataset are available".

Open GitHub and what's been released is the rotated-box version of NMS, a modified COCO evaluation tool, the rotation script that generates the SKU110K-R images, and the rotation convolution layer (with FSM inside). No training code, no inference code, and no DRH. The first line of the README reads "Work in process.", and the last update was in August 2020.

You can imagine the mood in the issues. In October 2020 someone opened an issue whose title is a straight-up rant. The author replied that, "because I was lazy and didn't get all the code organized", only the core part had been open-sourced for now, and that they "will keep working on the rest of the open-source release" (issue #12). For the better part of a year, people kept asking about progress in the thread, and one suggested switching to another paper, PIoU, saying they had already reproduced it. On the issue asking where DRH was, the author replied "The structure of DRHs is simple, we do not release the code." (issue #16).

In August 2021 someone asked "A year has passed. How is the work going?" (issue #23). In September 2024 people were still asking for the training and inference code (issue #25). The README still says Work in process (the progress bar must be stuck at 99%).

Also, someone compared the code with the paper and found that the FSM attention in the code first sums the three branches and then applies global average pooling, which amounts to channel attention, unlike the per-pixel weights the paper describes. The author replied that both versions are in the code, and the spatial attention from the paper is commented out (issue #13).

SKU110K-R, at least, is obtainable. The annotations are in COCO format on Google Drive; for the images, you download the original SKU-110K and convert them yourself with the authors' script. In an issue, the author mentioned that the full data is about 200 GB, and also pointed out that SKU-110K later released a revised version with 14 fewer training images and 5 fewer test images (issue #3).

Conclusion

DRN handles dense, tilted objects on two levels. FSM rotates the convolution's sampling grid as a whole by a predicted angle, then offers kernels of three shapes and lets each location pick; DRH has the classification and regression heads generate filters on the spot from the input and make small corrections to the predictions.

The actual gain on shelves is 1 to 1.5 mAP, and the bigger improvement comes from switching to CenterNet as the baseline itself. What it leaves the retail field for the longer term is SKU110K-R, the rotated-box version of SKU-110K, which later dense rotated-detection papers such as CFA also use as a benchmark.

If you want to start shelf detection from this paper, the dataset and evaluation tool are ready to use; for the model half, you'll have to write the training code and DRH yourself from the paper. The user in the issues who said they'd already reproduced PIoU was probably thinking along the same lines.