lilanxiao / Rotated_IoU

Differentiable IoU of rotated bounding boxes using Pytorch
MIT License
416 stars 64 forks source link

Bug in IOU_3d #18

Closed JonathanCMitchell closed 3 years ago

JonathanCMitchell commented 3 years ago

On this line: https://github.com/lilanxiao/Rotated_IoU/blob/master/oriented_iou_loss.py#L97 we shouldn't be multiplying by the union. After removing that I was able to converge

JonathanCMitchell commented 3 years ago

Or maybe that's not the case but for some reason I can't make it converge when that line is there.

lilanxiao commented 3 years ago

hi, I don't think that line is a bug.

intersection_3d = iou_2d * u * z_overlap

The iou_2d is multiplied with the union to get the area of the 2D intersection. Then, the area multiplied with the overlap in the z-axis makes the volume of the 3D intersection.

The non-convergence might be caused by something else. What loss value do you get, when you have a convergence issue?

I previously got NaN when I use this IoU-loss to train 3D detectors. The reason is, the functions which calculate the IoU and IoU-losses assume that the size of boxes is always positive. But sometimes, the network might predict non-positive values (e.g. if a fully connected layer without activation is used for box size regression, the predicted values are not limited). In this case, the functions might generate a crazy gradient and eventually break the training. The solution is simply limiting the range of box sizes in the network. I never have any convergence issue again after doing it.

JonathanCMitchell commented 3 years ago

How do you limit the range of box sizes in the network? Also are you able to guarantee the orientation? I see my orientation is either 180 degrees out of sync or I grow width, height, length in the negative direction.

lilanxiao commented 3 years ago

I just add something like sizes = torch.max(sizes, 1e-6) to force sizes to be positive. I have read #19 I think the misalignment of corners is an intended feature of IoU-loss.