IDEA-Research / detrex

detrex is a research platform for DETR-based object detection, segmentation, pose estimation and other visual recognition tasks.
https://detrex.readthedocs.io/en/latest/
Apache License 2.0
1.97k stars 206 forks source link

"dataloader.test.batch_size" > 1 when evaluation is not supported! #134

Open wanghao9610 opened 1 year ago

wanghao9610 commented 1 year ago

Hi: I want to set "dataloader.test.batch_size = 16" (default is 1) to accelerate the evaluation speed. But, I get a much smaller mAP results, e.g. 0.59 vs 41.5 mAP. Is it the upper stream(detectron2)'s issue? Could you fix the issue?

rentainhe commented 1 year ago

Hi: I want to set "dataloader.test.batch_size = 16" (default is 1) to accelerate the evaluation speed. But, I get a much smaller mAP results, e.g. 0.09 vs 41.5 mAP. Is it the upper stream(detectron2)'s issue? Could you fix the issue?

We will check this problem later~

rentainhe commented 1 year ago

Hi: I want to set "dataloader.test.batch_size = 16" (default is 1) to accelerate the evaluation speed. But, I get a much smaller mAP results, e.g. 0.09 vs 41.5 mAP. Is it the upper stream(detectron2)'s issue? Could you fix the issue?

We will check this problem this weekend, sry for the long time waiting

rentainhe commented 1 year ago

Hi: I want to set "dataloader.test.batch_size = 16" (default is 1) to accelerate the evaluation speed. But, I get a much smaller mAP results, e.g. 0.09 vs 41.5 mAP. Is it the upper stream(detectron2)'s issue? Could you fix the issue?

I was wondering which model you are used in this situation~ @wanghao9610

When setting test.batch_size > 1, the images of different image size will be padding into the same size as a batch input. And the padding part should be masked, however, for convenience, we ignored this situation before and used the same mask for each test image which may raise this issue, we will try to fix it.

rentainhe commented 1 year ago

Hi: I want to set "dataloader.test.batch_size = 16" (default is 1) to accelerate the evaluation speed. But, I get a much smaller mAP results, e.g. 0.09 vs 41.5 mAP. Is it the upper stream(detectron2)'s issue? Could you fix the issue?

You can try this solution if you're in a hurry by modifying the model like:

if self.training:
    batch_size, _, H, W = images.tensor.shape
    img_masks = images.tensor.new_ones(batch_size, H, W)
    for img_id in range(batch_size):
        img_h, img_w = batched_inputs[img_id]["instances"].image_size
        img_masks[img_id, :img_h, :img_w] = 0
else:
    batch_size, _, H, W = images.tensor.shape
    img_masks = images.tensor.new_ones(batch_size, H, W)
    for img_id in range(batch_size):
        img_h, img_w = images.image_sizes[img_id]
        img_masks[img_id, :(img_h-1), :(img_w-1)] = 0
wanghao9610 commented 1 year ago

Thanks for your immediate reply~ I will try your solution.

wanghao9610 commented 1 year ago

@rentainhe Hello, I have tried your provided solution, but I got the same much lower mAP result. Have you try it successfully?

rentainhe commented 1 year ago

@rentainhe Hello, I have tried your provided solution, but I got the same much lower mAP result. Have you try it successfully?

I was wondering which model you're testing under this situation @wanghao9610

I tried this on DINO-R50 with test-batch=2 each GPU, got 49.2AP

wanghao9610 commented 1 year ago

I run this on DN_DETR-R50 with you provided weight (dn_detr_r50_50ep.pth), setting "dataloader.test.batch_size=16" with 2gpus, got 0.59 AP. My tesing command as below: python ./tools/train_net.py --config-file projects/dn_detr/configs/dn_detr_r50_50ep.py --num-gpus 2 --eval-only train.init_checkpoint=work_dirs/dn_detr_r50_50ep/dn_detr_r50_50ep.pth train.output_dir=work_dirs/dn_detr_r50_50ep dataloader.test.batch_size=16. You could try this command and you will may get the result as same as my.

rentainhe commented 1 year ago

I run this on DN_DETR-R50 with you provided weight (dn_detr_r50_50ep.pth), setting "dataloader.test.batch_size=16" with 2gpus, got 0.59 AP. My tesing command as below: python ./tools/train_net.py --config-file projects/dn_detr/configs/dn_detr_r50_50ep.py --num-gpus 2 --eval-only train.init_checkpoint=work_dirs/dn_detr_r50_50ep/dn_detr_r50_50ep.pth train.output_dir=work_dirs/dn_detr_r50_50ep dataloader.test.batch_size=16. You could try this command and you will may get the result as same as my.

I will try to reproduce this issue later~

ihavision commented 1 year ago

Same problem. I also got <1% AP with DINO-R50 and dataloader.test.batch_size=8 on single GPU. The mask patch provided above doesn't make a difference.

theneotopia commented 9 months ago

Same problem, still not fixed yet. Experimented with DETR-R50 (converted) on a single RTX 3090 GPU, I got 0.9675 AP with test.batch_size=16, 7.37 AP with test.batch_size=4, 18.79 AP with test.batch_size=2, and 42.0 AP with test.batch_size=1. It seems that the evaluator only works correctly when the test.batch_size is set to 1.