Error calculating area "IndexError: too many indices for tensor of dimension 1"

Error calculating area "IndexError: too many indices for tensor of dimension 1"

我正在重新利用 here 中的一些代码来执行对象检测:

# 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])

在训练期间,我遇到了这个错误:

  File "c:21-mcm-master\src\PyTorch-RCNN\ui-prediction\src\screenshot_dataset.py", line 94, in __getitem__
    area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
IndexError: too many indices for tensor of dimension 1

根据建议 here,我发现我的一些图像不包含任何边界框并导致此错误:

# Create boxes list
boxes = [
    [annotation['xmin'], annotation['ymin'], annotation['xmax'], annotation['ymax']]
    for annotation in image_annotations
]

if len(boxes) == 0:
    print ("Help!")