将YoloV3输出转换为边界框,标签和置信度的坐标 [英] Convert YoloV3 output to coordinates of bounding box, label and confidence

查看:493
本文介绍了将YoloV3输出转换为边界框,标签和置信度的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行YoloV3模型并获取检测-3个条目的字典:

I run YoloV3 model and get detections - dictionary of 3 entries:


  1. detector / yolo-v3 / Conv_22 / BiasAdd / YoloRegion :具有
    形状的numpy.ndarray(1,255,52,52),

  2. detector / yolo-v3 / Conv_6 / BiasAdd / YoloRegion:具有$ b的numpy.ndarray $ b shape(1,255,13,​​13),

  3. detector / yolo-v3 / Conv_14 / BiasAdd / YoloRegion:numpy.ndarray,具有
    形状(1,255,26, 26)。

我知道字典中的每个条目都是对象检测的其他大小。
Conv_22适用于小型对象
Conv_14适用于中等对象
Conv_6适用于大型对象

I know that each entry in dictionary is other size of object detection. Conv_22 is for small objects Conv_14 is for medium objects Conv_6 is for big objects

如何将字典输出转换为边界框,标签和置信度的坐标?

How can I convert this dictionary output to coordinates of bounding box, label and confidence?

推荐答案

假定您使用python和opencv,

Presuming you use python and opencv,

请在需要的地方找到以下带有注释的代码,以使用cv2提取输出.dnn模块。

Pelase find the below code with comments where ever required, to extract the output using cv2.dnn module.

net.setInput(blob)

layerOutputs = net.forward(ln)

boxes = []
confidences = []
classIDs = []
for output in layerOutputs:
# loop over each of the detections
    for detection in output:
        # extract the class ID and confidence (i.e., probability) of
        # the current object detection
        scores = detection[5:]
        classID = np.argmax(scores)
        confidence = scores[classID]

        # filter out weak predictions by ensuring the detected
        # probability is greater than the minimum probability
        if confidence > threshold:
            # scale the bounding box coordinates back relative to the
            # size of the image, keeping in mind that YOLO actually
            # returns the center (x, y)-coordinates of the bounding
            # box followed by the boxes' width and height
            box = detection[0:4] * np.array([W, H, W, H])
            (centerX, centerY, width, height) = box.astype("int")

            # use the center (x, y)-coordinates to derive the top and
            # and left corner of the bounding box
            x = int(centerX - (width / 2))
            y = int(centerY - (height / 2))

            # update our list of bounding box coordinates, confidences,
            # and class IDs
            boxes.append([x, y, int(width), int(height)])
            confidences.append(float(confidence))
            classIDs.append(classID)
idxs = cv2.dnn.NMSBoxes(boxes, confidences, confidence, threshold)
#results are stored in idxs,boxes,confidences,classIDs

这篇关于将YoloV3输出转换为边界框,标签和置信度的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆