【问题标题】:How can I extract label from results in YOLO v5?如何从 YOLO v5 中的结果中提取标签?
【发布时间】:2022-08-20 20:57:44
【问题描述】:

有没有办法提取检测到的标签,如personcatdogresults.print() 函数打印的其他标签?我希望将这些检测到的标签保存在一个数组中并稍后使用。我在这里使用 YOLOv5 模型。

cap = cv2.VideoCapture(0)
while cap.isOpened():
    ret, frame = cap.read()
    
    # Make detections 
    results = model(frame)
    results.print()
    
    # Showing the box and prediction
    cv2.imshow(\'YOLO\', np.squeeze(results.render()))
    
    if cv2.waitKey(10) & 0xFF == ord(\'q\'):
        break
cap.release()
cv2.destroyAllWindows()

results.print() 的打印输出是这样的 -

image 1/1: 480x640 1 person
Speed: 7.0ms pre-process, 80.6ms inference, 3.5ms NMS per image at shape (1, 3, 480, 640)

从这个输出中,我想提取person 标签并将其存储在一个数组中。

    标签: deep-learning object-detection yolo yolov5


    【解决方案1】:

    假设您将 YoloV5 与 pytorch 一起使用,请参阅此 link。它详细说明了如何将结果解释为 json 对象,并解释了结构。

    【讨论】:

      【解决方案2】:

      这可能不是最佳解决方案,但这是我用于个人项目的一种方法:

      lst = []
      cap = cv2.VideoCapture(0)
      while cap.isOpened():
          ret, frame = cap.read()
          
          # Make detections
          results = model(frame)
          cv2.imshow('YOLO', np.squeeze(results.render())) 
          
          df = results.pandas().xyxy[0]
          
          for i in df['name']: # name->labels
              lst.append(i)
          
          
          if cv2.waitKey(10) & 0xFF == ord('q'):
              break
      cap.release()
      cv2.destroyAllWindows()
      

      我使用results.pandas().xyxy[0] 函数将结果作为数据框获取,然后将标签附加到列表中。

      【讨论】:

        猜你喜欢
        • 2022-08-20
        • 2022-08-19
        • 2022-07-29
        • 1970-01-01
        • 2019-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-20
        相关资源
        最近更新 更多