tryolabs / luminoth

Deep Learning toolkit for Computer Vision.
https://tryolabs.com
BSD 3-Clause "New" or "Revised" License
2.4k stars 400 forks source link

Concern regarding the IoU function #263

Open meyerjo opened 5 years ago

meyerjo commented 5 years ago

With boundingboxes a = [0, 0, 10, 10] b = [1, 1, 11, 11]

The intersection area of both boxes is from point [1, 1] to [10, 10]. The size is 81.

Each individual box has the size of 100. The union space is defined as:

union = (area_boxA + area_boxB - intersection) union = (100 + 100 - 81) = 119

Thus, the IoU is:

IoU = intersection / union IoU = 81 / 119 IoU = 0.68


In the given implementation, the following problem occurs.

During box area computation the height, width of the box is increased by "+ 1". Thus, the size of the boxes is too large. E.g. the boxes from above get a size of 121. The same happens in the intersection computation, which estimates the size as 100.

The resulting IoU:

IoU = 100 / (121 + 121 - 100) IoU = 0.704

Is overestimating the actual overlap of the both boxes.

The problem is clarified. If you just scale the coordinates of your bounding boxes. While the intersection regarding the union has to stay the same. In your implementation the IoU goes up from .7 to .96. Both of the test cases below illustrate the problem.

`

def testSameIoUDifferentScale(self):
    iou1 = self._get_iou([[0, 0, 10, 10]], [[1, 1, 11, 11]])
    iou2 = self._get_iou([[0., 0., 0.01, 0.01]], [[0.001, 0.001, 0.0011, 0.0011]])
    self.assertAllEqual(iou1, iou2)

def testOverlap(self):
    iou = self._get_iou([[0, 0, 10, 10]], [[1, 1, 11, 11]])
    self.assertAllEqual(iou, [[0.68067229]])

`