将YoloV3输出转换为边框、标签和机密的坐标

2024-05-13 00:57:08 发布

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

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

  1. “探测器/yolo-v3/Conv_22/BiasAdd/Yoloregon”:努比·恩达雷具有 形状(1255,52,52)
  2. “探测器/yolo-v3/Conv_6/BiasAdd/Yoloregon”:努比·恩达雷具有 形状(1255,13,13)
  3. “探测器/yolo-v3/Conv_14/BiasAdd/Yoloregon”:努比·恩达雷具有 形状(1255,26,26)。在

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

enter image description here

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


Tags: 对象模型目的字典yolo条目v3物体
1条回答
网友
1楼 · 发布于 2024-05-13 00:57:08

假设您使用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

相关问题 更多 >