【发布时间】:2021-06-14 19:28:41
【问题描述】:
我想根据检测分数计算检测到的对象。我正在使用 EdjeElectronics 的对象检测代码。这是我一直在使用的代码:
# Input tensor is the image
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Output tensors are the detection boxes, scores, and classes
# Each box represents a part of the image where a particular object was detected
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represents level of confidence for each of the objects.
# The score is shown on the result image, together with the class label.
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
这是检测线:
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: frame_expanded})
并使用它来可视化它:
# Draw the results of the detection (aka 'visulaize the results')
vis_util.visualize_boxes_and_labels_on_image_array(
frame,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8,
min_score_thresh=0.60)
我的问题是,我找到了一个视频,该视频告诉我如何根据分数(信心值)进行计数。但我不太清楚。
视频中的那个人使用这个循环来计算检测到的物体:
# Loop over all detections and draw detection box if confidence is above minimum threshold
for i in range (len(scores)):
if ((scores[i] > 0.6).all() and (scores[i] <= 1.0).all()):
current_count+=1
然后用这个在屏幕上打印出来:
# Draw framerate, current count, and total count in corner of frame
cv2.putText (frame,'Detections In Frame: ' + str(current_count),(30,75),cv2.FONT_HERSHEY_SIMPLEX,1,(98,189,184),2,cv2.LINE_AA)
到目前为止,我无法更新 current_count 值,我猜循环中有问题。所以,我无法计算检测到的对象,因为它总是显示0 值。请帮帮我
【问题讨论】:
-
也许您的结果都没有超过阈值?你把分数打印出来了吗?
-
当它检测到物体时,检测到的物体显示出 90% 的置信度。要么我在循环中使用了错误的变量,要么我不知道......
-
我认为分数是二维的,你看过形状吗?
len(detection_scores)可能会返回 1 -
我会尝试...抱歉我是新手
-
TypeError: len 对于符号张量没有很好的定义。 (detection_scores:0) 请致电
x.shape而不是len(x)获取形状信息。它给了我这样的错误
标签: tensorflow opencv machine-learning computer-vision object-detection