Error calculating area "IndexError: too many indices for tensor of dimension 1"
I'm repurposing some code from here to perform object detection:
# Create boxes list
boxes = [
    [annotation['xmin'], annotation['ymin'], annotation['xmax'], annotation['ymax']]
    for annotation in image_annotations
]

...

area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])

During training, I was hitting this error:
  File &quot;c:\2021-mcm-master\src\PyTorch-RCNN\ui-prediction\src\screenshot_dataset.py&quot;, line 94, in __getitem__
    area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
IndexError: too many indices for tensor of dimension 1


Following a suggestion here, I discovered some of my images did not contain any bounding boxes and was causing this error:
# Create boxes list
boxes = [
    [annotation['xmin'], annotation['ymin'], annotation['xmax'], annotation['ymax']]
    for annotation in image_annotations
]

if len(boxes) == 0:
    print (&quot;Help!&quot;)

