Python 计算模型连续预测同一标签的次数

Python 计算模型连续预测同一标签的次数,python,Python,在上面显示的一段代码中,我捕获相机的帧并使用检测方法识别对象,我对这些对象有一个预测,当这些对象被识别时,例如,我显示这些对象的相应图像。 我的问题是,如果第一次标签是dog,那么系统会再次尝试识别对象并预测标签,如果第二次检测到“dog”,让我们继续运行步骤4,否则,将不会执行步骤4。我如何执行? 我的最终目标是降低模型的敏感性。 我想到的是计算模型两次预测标签的次数,但我无法实现它。您想要的是一个有状态的系统,因此您必须存储以前的状态,以便能够在每次检测到某个东西时决定要做什么 例如,您可以

在上面显示的一段代码中,我捕获相机的帧并使用检测方法识别对象,我对这些对象有一个预测,当这些对象被识别时,例如,我显示这些对象的相应图像。 我的问题是,如果第一次标签是dog,那么系统会再次尝试识别对象并预测标签,如果第二次检测到“dog”,让我们继续运行步骤4,否则,将不会执行步骤4。我如何执行? 我的最终目标是降低模型的敏感性。
我想到的是计算模型两次预测标签的次数,但我无法实现它。

您想要的是一个有状态的系统,因此您必须存储以前的状态,以便能够在每次检测到某个东西时决定要做什么

例如,您可以使用collections.deque来实现此目的,请参见:


非常感谢,如果我想重复步骤,如果只预测一个特定的标签呢?例如,如果只有我的标签是“未知”,则重复检测,否则,在检测到每个标签(未知除外)后,将执行步骤4。只需添加一些条件测试if语句,将未知检测从步骤4中分支出来。我不知道opencv,所以在这方面我帮不了你太多忙哦,对不起,检测不是标签,我想保存标签。检测只是对象检测当每个对象面对摄像机时,执行检测,然后模型确定该对象是什么,然后决定标记什么。
cap = VideoStream().start()
while True:
            frame=cap.read()
            Detect = detection_method(frame)
            if detect:
                Predict_label=function(recognize)
            (Step 4)#Do somthing on this predict_label

cv2.destroyAllWindows()
vs.stop()   
Label is for example:unknown,cat,dog,panda,...
cap = VideoStream().start()
previous_detections = collections.dequeue(maxlen=5) # adapt for your own purposes
while True:
        frame = cap.read()
        detection = detection_method(frame)
        previous_detections.append(detection) # store the detection
        if detection:
            # use all previous states for your own logic
            # I am not familiar with opencv so this will likely not work, consider it pseudo-code
            # this is supposed to check if all previous known detections are the same as the current one
            if all(previous_detection == detection for previous_detection in previous_detections):
                predict_label = function(recognize)
                (Step 4)#Do somthing on this predict_label

cv2.destroyAllWindows()
vs.stop()