【问题标题】:PyTorch YoloV5 model different results?PyTorch YoloV5 模型结果不同?
【发布时间】:2021-09-27 12:01:24
【问题描述】:

我正在尝试对视频进行对象检测,我使用了 YoloV5S。有两种识别对象的方法。

1) 首先是从 torch.hub.load() 加载模型

2) 第二个来自 python detect.py

我从两种方法而不是相同的结果在同一视频上得到不同的结果。如果我只是使用

!python detect.py --weights 'yolov5s.pt' --conf-thres=0.25 --source /home/hamza/Desktop/House_Video.mp4 

我得到了检测到不同计数对象的结果,例如在这个视频的最后一帧中,我得到了 3 把椅子、1 张餐桌和 1 个时钟,但是如果我使用下面的代码 (torch.hub.加载) 。我要 3 把椅子和 1 张餐桌。所有帧都一样,此方法中缺少一些对象,第一种方法具有。

我的代码:

import cv2, torch
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
model.conf = 0.25

list_of_original_frames = []
list_of_detected_classes_in_all_frames = []
detected_classes = []
check_dict = {}

def detect_video(video_path):

    cap = cv2.VideoCapture(video_path)
    while (cap.isOpened()):
        ret, frame = cap.read()
        if ret == False:
            break
        list_of_original_frames.append(frame)
    cap.release()
    cv2.destroyAllWindows()

    for file in list_of_original_frames:
        results = model(file)
        new_df = results.pandas()
        new_result = new_df.xywh[0]['name']
        list_of_detected_classes_in_all_frames.append(new_result.tolist())
   
    
    for outer_loop in list_of_detected_classes_in_all_frames:
        for inner_loop in outer_loop:
            if inner_loop:
                detected_classes.append(inner_loop)

    for iterate in detected_classes:
        if iterate not in check_dict:
            check_dict[iterate] = 1
        else:
            check_dict[iterate] = check_dict[iterate] + 1
    
    return check_dict
video_path = '/home/hamza/Desktop/House_Video.mp4'
check_dict = detect_video(video_path)

我做错了哪一部分?

【问题讨论】:

    标签: python list computer-vision object-detection yolo


    【解决方案1】:

    model = torch.hub.load('ultralytics/yolov5', 'custom', path='path/to/best.pt') # 默认

    model = torch.hub.load('path/to/yolov5', 'custom', path='path/to/best.pt', source='local') # 本地仓库

    【讨论】:

    • 我认为这不能解决问题。在我看来,OP 加载模型并不困难,我认为他们正在寻求使用它的帮助。
    猜你喜欢
    • 2021-03-29
    • 1970-01-01
    • 2021-08-03
    • 2021-11-11
    • 2022-09-28
    • 2021-08-28
    • 1970-01-01
    • 2021-12-10
    • 2021-06-08
    相关资源
    最近更新 更多