如何处理YOLOv2的框边界结果

时间:2019-06-23 09:10:08

标签: python yolo darkflow

很抱歉,我对AI的了解有限。但是我正在尝试使用YOLOv2(特别是darkflow)来识别我的对象。我有100张图片,并且训练了1000个纪元。但是,我的输出实际上并不是我在线阅读的说明。出现太多的装箱框,图片中我只能识别一个对象。这是我的测试文件。我也想知道“阈值”在“选项”中的作用。我的问题目前在哪里?请让我知道。

from darkflow.net.build import TFNet
import numpy as np
import cv2
import time
import pprint as pp

options = {
            "model": "cfg/yolov2-voc-1c.cfg",
            "load": -1,
            "threshold": 0.01
        }

tfnet2 = TFNet(options)

tfnet2.load_from_ckpt()

def boxing(original_img, predictions):
    newImage = np.copy(original_img)

    for result in predictions:
        top_x = result['topleft']['x']
        top_y = result['topleft']['y']

        btm_x = result['bottomright']['x']
        btm_y = result['bottomright']['y']

        confidence = result['confidence']
        label = result['label'] + " " + str(round(confidence, 3))

        if confidence > 0.06:
            newImage = cv2.rectangle(newImage, (top_x, top_y), (btm_x, btm_y), (255,0,0), 3)
            newImage = cv2.putText(newImage, label, (top_x, top_y-5), cv2.FONT_HERSHEY_COMPLEX_SMALL , 0.8, (0, 230, 0), 1, cv2.LINE_AA)

    return newImage

original_img = cv2.imread("data_test.jpg")
original_img = cv2.cvtColor(original_img, cv2.COLOR_BGR2RGB)
result = tfnet2.return_predict(original_img)

new_frame = boxing(original_img, result)

cv2.imwrite('output.jpg', new_frame)

结果图片:

enter image description here

1 个答案:

答案 0 :(得分:1)

您使用的阈值非常低= 0.01,这意味着如果概率大于1%,则模型将认为已检测到对象,通常我们使用大于25%的阈值。 还可以考虑更改置信度。

相关问题