TypeError:“浮动”对象在活动对象检测中不可迭代

时间:2019-06-13 15:44:50

标签: python

我是Python的新手,在从事有关活动对象检测的GitHub项目时,遇到此错误。

File "C:\Users\pankaj\Documents\models\object_detection\utils\visualization_utils.py", line 759, in visualize_boxes_and_labels_on_image_array
    box = tuple(boxes[i].tolist())

TypeError: 'float' object is not iterable

这是我的代码:

# Create a display string (and color) for every box location, group any boxes
# that correspond to the same location.
box_to_display_str_map = collections.defaultdict(list)
box_to_color_map = collections.defaultdict(str)
box_to_instance_masks_map = {}
box_to_instance_boundaries_map = {}
box_to_keypoints_map = collections.defaultdict(list)
box_to_track_ids_map = {}
if not max_boxes_to_draw:
    max_boxes_to_draw = boxes.shape[0]
for i in range(min(max_boxes_to_draw, boxes.shape[0])):
    if scores is None or scores[i] > min_score_thresh:
        box = tuple(boxes[i].tolist())  # **This is the line error is referencing to**
    if instance_masks is not None:
        box_to_instance_masks_map[box] = instance_masks[i]
    if instance_boundaries is not None:
        box_to_instance_boundaries_map[box] = instance_boundaries[i]
    if keypoints is not None:
        box_to_keypoints_map[box].extend(keypoints[i])
    if track_ids is not None:
        box_to_track_ids_map[box] = track_ids[i]
    if scores is None:
        box_to_color_map[box] = groundtruth_box_visualization_color
    else:
        display_str = ''

我该如何解决?这实际上意味着什么?

1 个答案:

答案 0 :(得分:1)

boxes[i].tolist()返回单个浮点值,但是tuple()要求其参数可迭代,并且单个浮点数不可迭代。

考虑到函数名称tolist(),看来该函数应该以列表形式返回单个项目。

一种快速解决方案可能是将结果强制为列表,如下所示:

box = tuple([boxes[i].tolist()])

但这似乎是一个糟糕的解决方案,因为如果tolist()确实返回了实际列表,这将迫使它成为列表列表,这可能不是您想要的。

似乎真正的解决方案是修改tolist()以始终返回列表,即使它只是一项。