I run into an error when trying to run detect.py to view a pre-trained model in yolov7

205 Views Asked by At

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].

Install cuda, cudnn, pythorch and the requirements, I don't know if it is some version incompatibility, but I have checked it anyway, any idea what it could be?

1

There are 1 best solutions below

0
On

You don't appear to have the right torch back-end installed.

Basically, because Torch is so highly optimized and uses your GPU in a quite specialized manner, you need to install the right version of torch for your GPU, and then specify what version you have installed in the Code.

Based on the error message, you have currently selected the CUDA back-end in code, which is for NVidia cards. If you do have a card of that brand, you have not installed torch for it properly. If you don't, you should edit the piece of code that specifies CUDA, and then again assert that you have torch installed for that card correctly.

To learn how to properly install Torch, you should look here