计算区域“索引器错误:维度1张量的索引太多”

2024-03-28 23:02:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在重新利用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:\2021-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

Tags: 对象代码insrc利用forherecreate
1条回答
网友
1楼 · 发布于 2024-03-28 23:02:10

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

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

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

相关问题 更多 >