将 YoloV3 输出转换为边界框、标签和置信度的坐标

gal*_*hem 5 python computer-vision tensorflow yolo

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

  1. " detector/yolo-v3/Conv_22/BiasAdd/YoloRegion" :numpy.ndarray 形状为 (1,255,52,52),
  2. “Detector/yolo-v3/Conv_6/BiasAdd/YoloRegion”:形状为 (1,255,13,​​13) 的 numpy.ndarray,
  3. “Detector/yolo-v3/Conv_14/BiasAdd/YoloRegion”:形状为 (1,255,26,26) 的 numpy.ndarray。

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

在此输入图像描述

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

ven*_*nan 2

假设你使用 python 和 opencv,

Pelase 找到下面的代码,并在需要的地方添加注释,以使用 cv2.dnn 模块提取输出。

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
Run Code Online (Sandbox Code Playgroud)

  • 我只想注意一点:计算盒子所有四个角的 X/Y 坐标的正确数学方法位于原始 YOLO 源代码中,此处:https://github.com/pjreddie/darknet/blob/810d7f797bdb2f021dbe65d2524c2ff6b8ab5c8b/ src/image.c#L283-L291 (3认同)