facebookresearch / detr

End-to-End Object Detection with Transformers
Apache License 2.0
13.51k stars 2.44k forks source link

Bbox from dataset triggers assert error, would you have any advice on how to set the dataset properly? #459

Open pikouli opened 3 years ago

pikouli commented 3 years ago

Hi, I am trying to use a custom dataset but the following error gets triggered:

~/detr-main/util/box_ops.py in generalized_box_iou(boxes1, boxes2)
     51    # print(boxes2)
     52     assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
---> 53     assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
     54     iou, union = box_iou(boxes1, boxes2)
     55 

AssertionError: 

It seems to come from my dataset as boxes2 are the target values. When printing the tgt_box used in matcher I get the following tensor which looks not appropriate:

tensor([[  78125.0000,   97656.2500, -156250.0000, -195312.5000],
        [ -78124.0000,   97656.2500, -156250.0000, -195312.5000]],
       device='cuda:0')

I have tried simplifying the dataset and annotations. I am now using a dataset with two images and the following instances annotations:

    data = {}
    data['licenses']={}
    data['info']={}
    data['images']=[{'file_name':"000000142238.jpg","height":512,"width":640,"id":142238},
{'file_name':"000000439180.jpg","height":512, "width":640, "id":439180}]
    data['categories']=[{"supercategory":"person","color":[220,20,60], "id":1, "name":"person"}]
    data['annotations']=[{'segmentation': {}, 'area': 477, 'iscrowd': int(0), 'image_id': 142238, 'bbox': [20, 183, 49, 173], 'category_id': 1, 'id': 1},
                         {'segmentation': {}, 'area': 311, 'iscrowd': int(0), 'image_id': 439180, 'bbox': [20, 160, 43, 77], 'category_id': 1, 'id': 19}]

and these panoptic annotations:

    data = {}
    data['licenses']={}
    data['info']={}
    data['images']=[{'file_name':"000000142238.jpg","height":512,"width":640,"id":142238},
{'file_name':"000000439180.jpg","height":512, "width":640, "id":439180}]
    data['categories']=[{"supercategory":"person","color":[220,20,60], "id":1, "name":"person"}]
    data['annotations']=[{'segments_info': [{'category_id': 1, 'id': 4260062, 'area': 477,'iscrowd': int(0),'bbox': [20, 183, 49, 173]}], 'file_name': '000000142238.png', 'image_id': 142238}, 
     {'segments_info': [{'category_id': 1, 'id': 2823390, 'area':311, 'iscrowd': int(0), 'bbox': [20, 160, 43, 77]}], 'file_name': '000000439180.png', 'image_id': 439180}]

I am using torchvision 0.6.0 and torch 1.5.0.

I can't get my head around what would be the problem. The image size correspond to the real image sizes and bounding boxes seem non-degenerated and not exceeding the images bounds. I am not sure how to compute the area though. Would you please have any clue of what is triggering the error?

For instance, must it be the case that there is at least one pixel of the color of the category in each bounding box? What are the constraint on the dataset?

sonhua commented 2 years ago

Not sure if this applies to your case, but in my case, this is because the width and height of the predicted box are negative, causing the box in XYXY format to degenerate.

In the original code the predicted box size is normalized by a sigmoid function so this error does not happen. But if your code does not do that, you need to ensure the box is valid before computing the gIoU.

My current fix is to take width = exp(width) to make sure the value is positive and there is no degeneration.

Sahar-DataScience commented 2 years ago

did you find a solution ? I'am facing the same problem, I'm trying to do instance segmentation

aleenarayamajhi commented 1 year ago

Hi did you fix the problem? I'm getting same error for custom dataset in coco format.

fxhaaa commented 12 months ago

File "/home/cqupt/fxh/detr-main/models/matcher.py", line 74, in forward cost_giou = -generalized_box_iou(box_cxcywh_to_xyxy(out_bbox), box_cxcywh_to_xyxy(tgt_bbox)) File "/home/cqupt/fxh/detr-main/util/box_ops.py", line 51, in generalized_box_iou assert (boxes1[:, 2:] >= boxes1[:, :2]).all() RuntimeError: CUDA error: device-side assert triggered terminate called after throwing an instance of 'std::runtime_error' what(): NCCL error in: /pytorch/torch/lib/c10d/../c10d/NCCLUtils.hpp:136, unhandled cuda error, NCCL version 2.7.8

I met this error,can you tell me how can I solve it?Thanks a lot.