我使用的代码是:https://www.edureka.co/blog/tensorflow-object-detection-tutorial/。在行:vis_util.visualize_boxes_and_labels_on_image_array(和Get the bounding box coordinates in the TensorFlow object detection API tutorial中,我使用了Vadim的代码:Get the bounding box coordinates in the TensorFlow object detection API tutorial如下:
#so detection has happened and you've got output_dict as a
# result of your inference
# then assume you've got this in your inference.py in order to draw rectangles
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8)
# This is the way I'm getting my coordinates
boxes = output_dict['detection_boxes']
# get all boxes from an array
max_boxes_to_draw = boxes.shape[0]
# get scores to get a threshold
scores = output_dict['detection_scores']
# this is set as a default but feel free to adjust it to your needs
min_score_thresh=.5
# iterate over all objects found
for i in range(min(max_boxes_to_draw, boxes.shape[0])):
#
if scores is None or scores[i] > min_score_thresh:
# boxes[i] is the box which will be drawn
class_name = category_index[output_dict['detection_classes'][i]]['name']
print ("This box is gonna get used", boxes[i], output_dict['detection_classes'][i])我要疯了!错误:
output_dict['detection_boxes'],
KeyError: 'detection_boxes'我在谷歌和堆叠溢出上搜索了很多小时。我没找到有用的东西。有人知道该怎么做吗?
更新(12/08/2022):我在整个def run_inference_for_single_image(image, graph):中添加了打印:
ops = []
all_tensor_names = set()
tensor_name = num_detections:0
tensor_name = detection_boxes:0
tensor_name = detection_scores:0
tensor_name = detection_classes:0
tensor_name = detection_masks:0
returned output_dict = {}
output_dict = {}
Traceback (most recent call last):
File "/home/someone/Desktop/test/test_code.py", line 132, in <module>
output_dict['detection_boxes'],
KeyError: 'detection_boxes'出于某种原因,它确实读取了文件中的任何内容,对吗?你看到什么我不知道的东西了吗?有什么想法吗?
发布于 2022-08-12 09:04:20
正如我在注释中所说的,从错误来看,output_dict似乎没有键"detection_boxes"。OP还确认了负责创建dict、run_inference_for_single_image(image, graph)的函数输出一个空的output_dict。
所以问题就在这个函数中,很可能是作为参数传递的。您应该对函数进行一些调试,可能会打印内部的变量来发现问题。告诉我是怎么回事!
https://stackoverflow.com/questions/73326997
复制相似问题