ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
28.57k stars 5.68k forks source link

NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. #10195

Closed MuhammadSuhaib01 closed 3 months ago

MuhammadSuhaib01 commented 5 months ago

Search before asking

YOLOv8 Component

Other

Bug

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, Meta, QuantizedCPU, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradMPS, AutogradXPU, AutogradHPU, AutogradLazy, AutogradMeta, Tracer, AutocastCPU, AutocastCUDA, FuncTorchBatched, BatchedNestedTensor, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].

Environment

Ultralytics YOLOv8.1.32 🚀 Python-3.11.4 torch-2.2.1+cu121 CUDA:0 (NVIDIA GeForce RTX 3050 Laptop GPU, 4096MiB) Setup complete ✅ (12 CPUs, 13.9 GB RAM, 321.6/465.7 GB disk)

Minimal Reproducible Example

import cv2 from ultralytics import YOLO

Load your model

model = YOLO('D:/Work Space/Python Development/Virtual Enviroment/Pose Detection With Reps Count/yolov8s-pose.pt')

Open the video

cap = cv2.VideoCapture("gymvideo.mp4")

Process each frame

while cap.isOpened(): ret, frame = cap.read() if not ret: break

# Run model prediction
results =  model('gymvideo.mp4',stream=False)

for r in results:
    boxes = r.boxes  # Boxes object for bbox outputs      
    masks = r.masks  # Masks object for segment masks outputs
    probs = r.probs  # Class probabilities for classification outputs

# Extract keypoints
keypoints = results[0].keypoints

# Draw keypoints on the frame
for kpt in keypoints.xy:
    x = int(kpt[0][0]) 
    y = int(kpt[0][1])
    cv2.circle(frame, (x, y), radius=3, color=(0, 255, 0), thickness=-1)

# Show the frame with keypoints
cv2.imshow('Keypoints without lines', frame)

# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

Release the video capture object and close all windows

cap.release() cv2.destroyAllWindows()

Additional

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, Meta, QuantizedCPU, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradMPS, AutogradXPU, AutogradHPU, AutogradLazy, AutogradMeta, Tracer, AutocastCPU, AutocastCUDA, FuncTorchBatched, BatchedNestedTensor, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].

This is the complete error. I have re-installed cuda, cudnn and pytorch with several versions upgrading and downgrading their versions still i am facing the same issue can someone help me?

Are you willing to submit a PR?

github-actions[bot] commented 5 months ago

👋 Hello @MuhammadSuhaib01, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 5 months ago

Hi there! 😊 It looks like you're encountering an issue with the Non-Maximum Suppression (NMS) function from torchvision not being compatible with the 'CUDA' backend. This issue may be related to the version compatibility between PyTorch, torchvision, and CUDA. Given your setup, here are a couple of things you might try:

  1. Ensure Compatibility: Double-check that your PyTorch and torchvision versions are compatible with each other and with CUDA 12.1. PyTorch's previous versions page can be particularly helpful for finding compatible versions.

  2. Reinstall torchvision: Sometimes, a fresh installation of torchvision may resolve backend issues. Be sure to match the torchvision version with your PyTorch installation:

    pip install torch torchvision --upgrade
  3. Check CUDA Toolkit: Make sure your system's CUDA toolkit version matches the version supported by PyTorch. Different versions of PyTorch may require specific versions of CUDA.

If you've tried these steps and the problem persists, it might help to provide more information on the versions of torchvision you've tried, as well as confirming the CUDA toolkit version installed on your system. Sometimes, the devil's in the details with version-specific issues.

Keep us posted on how it goes, and we'll do our best to help you get it sorted! 🚀

github-actions[bot] commented 4 months ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐