计算mod连续预测同一标签的次数

2024-03-28 21:51:29 发布

您现在位置:Python中文网/ 问答频道 /正文

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,...

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


Tags: 对象模型trueread步骤标签framestart
1条回答
网友
1楼 · 发布于 2024-03-28 21:51:29

您需要的是一个有状态的系统,因此您必须存储以前的状态,以便在每次检测到某些内容时能够决定要执行的操作。你知道吗

例如,可以使用collections.deque来实现这一点,请参见doc

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()   

相关问题 更多 >