我在尝试运行 detector.py 以查看 yolov7 中预训练的模型时遇到错误

问题描述 投票:0回答:1

python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg
Namespace(weights=['yolov7.pt'], source='inference/images/horses.jpg', img_size=640, conf_thres=0.25, iou_thres=0.45, device='', view_img=False, save_txt=False, save_conf=False, nosave=False, classes=None, agnostic_nms=False, augment=False, update=False, project='runs/detect', name='exp', exist_ok=False, no_trace=False)
YOLOR  52f8176 torch 2.1.1+cu118 CUDA:0 (NVIDIA GeForce GTX 1650, 4095.75MB)

Fusing layers...
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
C:\Users\aleja\anaconda3\envs\yolov7-gpu-env\lib\site-packages\torch\functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ..\aten\src\ATen\native\TensorShape.cpp:3527.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Model Summary: 306 layers, 36905341 parameters, 6652669 gradients, 104.5 GFLOPS
 Convert model to Traced-model...
 traced_script_module saved!
 model is traced!

Traceback (most recent call last):
  File "C:\yolov7-gpu\detect.py", line 201, in <module>
    detect()
  File "C:\yolov7-gpu\detect.py", line 97, in detect
    pred = non_max_suppression(pred, opt.conf_thres, opt.iou_thres, classes=opt.classes, agnostic=opt.agnostic_nms)
  File "C:\yolov7-gpu\utils\general.py", line 713, in non_max_suppression
    i = torchvision.ops.nms(boxes, scores, iou_thres)  # NMS
  File "C:\Users\aleja\anaconda3\envs\yolov7-gpu-env\lib\site-packages\torchvision\ops\boxes.py", line 41, in nms
    return torch.ops.torchvision.nms(boxes, scores, iou_threshold)
  File "C:\Users\aleja\anaconda3\envs\yolov7-gpu-env\lib\site-packages\torch\_ops.py", line 692, in __call__
    return self._op(*args, **kwargs or {})
NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'torchvision::nms' is only available for these backends: [CPU, QuantizedCPU, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradMPS, AutogradXPU, AutogradHPU, AutogradLazy, AutogradMeta, Tracer, AutocastCPU, AutocastCUDA, FuncTorchBatched, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].

安装cuda、cudnn、pythorch和要求,我不知道是不是版本不兼容,但我还是检查了,知道可能是什么吗?

python deep-learning pytorch torchvision yolov7
1个回答
0
投票

您似乎没有安装正确的手电筒后端。

基本上,由于 Torch 进行了高度优化,并且以非常专业的方式使用您的 GPU,因此您需要为您的 GPU 安装正确版本的 torch,然后在代码中指定您安装的版本。

根据错误消息,您当前在代码中选择了

CUDA
后端,该后端适用于 NVidia 卡。如果您确实有该品牌的卡,则说明您尚未正确安装该卡。如果不这样做,您应该编辑指定
CUDA
的代码段,然后再次断言您已正确为该卡安装了 torch。

要了解如何正确安装 Torch,您应该查看 这里

© www.soinside.com 2019 - 2024. All rights reserved.