XinzeLee / PolygonObjectDetection

This repository is based on Ultralytics/yolov5, with adjustments to enable polygon prediction boxes.
352 stars 95 forks source link

Strange behaviour in overlapping bounding boxes #17

Closed AntMorais closed 2 years ago

AntMorais commented 2 years ago

@XinzeLee I have an issue when there are two adjacent or overlapping objects that I want to detect. I created a diagram to give an example.

PolygonProblem

The objects I am trying to detect have a rectangular shape and are represented in the image by black rectangles with grey outlines. The bounding boxes predicted by the model are in red.

As you can see, box 1 and 3 are correct and box 2 is incorrect. Increasing the confidence or decreasing the IoU threshold cause only box 2 to be visible.

This happens in almost every case where 2 or more objects are close together.

Any idea on the root of the problem?

XinzeLee commented 2 years ago

From what you have mentioned, clearly the model is giving the box 2 a higher confidence than the other box 1 and 3, explaining why increasing confidence threshold or reduce IoU threshold won't help.

Regarding this issue, I have several possible solutions for your:

  1. Check your training process carefully. Is the training process already overfitting or still underfitting. If it is overfitting, try to reduce the training epochs. If it is underfitting, then try to allow the model to train more.
  2. If the training process is not the reason, then maybe assign a higher weight to the object loss (lobj). It might help with the wrong boxing problem.
AntMorais commented 2 years ago

The model was in fact overfitting. I improved the problem by adding more data and making sure I don't overfit. I also changed the way I annotate the images by making the bounding boxes tighter on the body of the object, so that there is less overlap between the bounding boxes of different objects. Thank you for you answer and great work on this repo!