我是张力流的新手。我对如何计算使用 TensorFlow对象检测API 检测到的对象数量感到困惑?
# Score is shown on the result image, together with the class label.
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
if image_np_expanded is not None:
# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict={image_tensor: image_np_expanded}
)
由于 num_detections 是 numpy.ndarray ,我试图检索它的长度但不起作用。
num_detections.size
>> 1
既不使用张量长度:
tf.size(num_detections, out_type=tf.int32)
>> 1
在我的情况下,检测到的对象数量不止一个。
答案 0 :(得分:1)
我一直在做类似的过程但是工作流程不同。我重写了object_detection笔记本中的教程代码,如下所示。它捕获检测框,类和概率的输出,并忽略通过推理的任何图像处理。对于我的情况,我将结果转储到JSON文件中并将它们导入到另一个程序中以完成我的分析(确定检测数量)但如果python是你的东西,我认为你可以处理“myResults”来得到你的答案。 / p>
myResults = collections.defaultdict(list)
for image_path in TEST_IMAGE_PATHS:
if os.path.exists(image_path):
image = Image.open(image_path)
# the array based representation of the image will be used later in order to prepare the
# result image with boxes and labels on it.
image_np = load_image_into_numpy_array(image)
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
output_dict = run_inference_for_single_image(image_np, detection_graph)
# Visualization of the results of a detection.
op=get_scores(
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
min_score_thresh=.2)
myResults[image_path].append(op)