yolov5+deepsort跑通了,视频画面却没有结果

之前的代码还可以,但是换了个电脑之后,重新从github上下载代码,结果运行出来之后,视频没有结果,测试yolov5_deepsort的时候出现的错误。于是找呀找呀。终于找到了问题。
在这里插入图片描述

运行没有结果
在detecor.py文件中,加入 cudnn.benchmark = True 就可以了。

 if webcam:
        view_img = check_imshow()
        cudnn.benchmark = True  # set True to speed up constant image size inference
        dataset = LoadStreams(source, img_size=imgsz, stride=stride)
    else:
        cudnn.benchmark = True

        dataset = LoadImages(source, img_size=imgsz, stride=stride)

检测结果
在这里插入图片描述
,同理在track.py中也加入这句话就可以了

    if show_vid:
        show_vid = check_imshow()

    if webcam:
        cudnn.benchmark = True  # 设置 True 以加速恒定图像尺寸推断
        dataset = LoadStreams(source, img_size=imgsz, stride=stride)
    else:
        cudnn.benchmark = True
        dataset = LoadImages(source, img_size=imgsz)

补充

在github上下载了封装yolov5检测,然后deepsort跟踪的,结果运行完后也没有结果,在这里插入图片描述
同样也是在封装的detector中,在数据处理函数中加入这句话 cudnn.benchmark = True

    def preprocess(self, img):
        cudnn.benchmark = True
        img0 = img.copy()
        img = letterbox(img, new_shape=self.img_size)[0]
        img = img[:, :, ::-1].transpose(2, 0, 1)
        img = np.ascontiguousarray(img)
        img = torch.from_numpy(img).to(self.device)
        img = img.half()  # 半精度
        img /= 255.0  # 图像归一化
        if img.ndimension() == 3:
            img = img.unsqueeze(0)

        return img0, img

之后就有结果了

猜你喜欢

转载自blog.csdn.net/gubeiqing/article/details/120208518