如何使用张量流模型对对象进行计数?

How to count objects using tensorflow model?

我想根据检测分数对检测到的对象进行计数。我正在使用 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 值。请帮助我

试试这个

for box,score,cls in zip(boxes[0],scores[0],classes[0]):
    if score >= 0.6 and score <= 1.0:
        count += 1