rf-detr icon indicating copy to clipboard operation
rf-detr copied to clipboard

Bboxes with too high overlap

Open panagiotamoraiti opened this issue 8 months ago • 11 comments

Hello,

I've recently started to use rf-detr and i observe that in my case there are many overlapping bboxes and sometimes the overlap is perfect and 2 labels are assigned to the same object. Any suggestions about this issue?

panagiotamoraiti avatar Apr 29 '25 13:04 panagiotamoraiti

I have experienced the same issue

ginobili avatar Apr 29 '25 18:04 ginobili

+1

ews-grmunjal avatar Apr 30 '25 10:04 ews-grmunjal

@isaacrob-roboflow Any suggestions about this, or possible solutions?

panagiotamoraiti avatar Apr 30 '25 11:04 panagiotamoraiti

hi! interesting issue :) can you share some examples?

if you know ahead of time that you have a prior on maximum overlap, you COULD always apply NMS on top of RF-DETR outputs. that forces your prior on max overlap to be observed, which should improve mAP for cases where you have such a prior (at the cost of course of slower inference).

however, the model SHOULD learn not to do that, given sufficient data. I would love to see more about your usecase!

isaacrob-roboflow avatar May 05 '25 19:05 isaacrob-roboflow

@isaacrob-roboflow, as I mentioned in Chicago, I’ve experienced similar issues myself.

@panagiotamoraiti, @ginobili, @ews-grmunjal — applying NMS should resolve your issue. You can do this by calling .with_nms(threshold=0.5). For example:

from PIL import Image
from rfdetr import RFDETRBase

model = RFDETRBase(...)
image = Image.open(...)
detections = model.predict(image, threshold=0.5).with_nms(threshold=0.5)

SkalskiP avatar May 06 '25 09:05 SkalskiP

Thanks a lot for your help. In my case training for more epochs has reduced significantly the high overlapping predictions. I have a dataset of ~1000 images with ~5-25 instances in every image. When i trained for 10 epochs i got mAP metrics over 90% but i had many high-overlapping predictions. For now I've trained for 20 epochs and most high-overlapping bboxes have disappear. However some still remain, so applying NMS on top may help. Also, maybe i should train more because i think my dataset is big enough.

panagiotamoraiti avatar May 06 '25 13:05 panagiotamoraiti

@panagiotamoraiti I would imagine 10 epochs is under training. I would encourage you to train for longer. We don't use any schedulers so honestly you can just set it to go for 100 and take the best checkpoint, that'll give the same result as if you'd set it to the optimal number originally.

@SkalskiP how long are you training yours? I totally buy that this behavior might happen early in training but then go away with additional training.

isaacrob-roboflow avatar May 06 '25 14:05 isaacrob-roboflow

@isaacrob-roboflow I agree, that sounds plausible. I'm starting work on the Basketball AI project this week and will be training quite a few models. I’ll try to keep an eye on this as I go.

SkalskiP avatar May 07 '25 10:05 SkalskiP

@ews-grmunjal how large is your dataset? how many objects appear in a single image?

isaacrob-roboflow avatar May 14 '25 16:05 isaacrob-roboflow

Hello, i've observed that the issue persists in another dataset. Now i fine-tune the pre-trained rfdetr on an animal dataset i downloaded from kaggle.

These are my classes: ['Brown bear', 'Red panda', 'Eagle', 'Deer', 'Owl', 'Butterfly', 'Monkey', 'Duck', 'Sparrow', 'Tiger', 'Woodpecker', 'Tortoise', 'Fox', 'Squirrel', 'Rabbit', 'Canary', 'Raccoon', 'Parrot']

The training stopped at epoch 10 using early stopping and achieving map@50 0.927 and map@50-95 0.833. I get several examples where more than one class ids have been predicted for one animal. If you are interested in searching that issue i would be happy to help and provide further information.

Image Image Image Image Image Image

Raising the confidence threshold, which now is 0.25, can reduce such examples, but it doesn't eliminate them completely. I am curious why the network exhibits such behavior.

@isaacrob-roboflow

panagiotamoraiti avatar Jul 18 '25 14:07 panagiotamoraiti

I have the same problem on the default model trained on coco

francescobodria avatar Nov 12 '25 14:11 francescobodria