gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:43:19 31 4
gpt4 key购买 nike

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

  • “检测器/yolo-v3/Conv_22/BiasAdd/YoloRegion”:numpy.ndarray
    形状 (1,255,52,52),
  • “检测器/yolo-v3/Conv_6/BiasAdd/YoloRegion”:numpy.ndarray
    形状 (1,255,13,​​13),
  • “检测器/yolo-v3/Conv_14/BiasAdd/YoloRegion”:numpy.ndarray
    形状(1,255,26,26)。

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

    enter image description here

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

    最佳答案

    假设你使用 python 和 opencv,

    请在需要的地方找到以下带有注释的代码,以使用 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

    关于python - 将 YoloV3 输出转换为边界框、标签和置信度的坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57753640/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com