ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.2k stars 16.43k forks source link

AssertionError: CUDA unavailable, invalid device 0 requested #474

Closed yancccc closed 4 years ago

yancccc commented 4 years ago

~/yolov5-master$ python detect.py --source ./inference/images/ --weights yolov5s.pt --conf 0.4 --device 0 Namespace(agnostic_nms=False, augment=False, classes=None, conf_thres=0.4, device='0', img_size=640, iou_thres=0.5, output='inference/output', save_txt=False, source='./inference/images/', update=False, view_img=False, weights=['yolov5s.pt']) False Traceback (most recent call last): File "detect.py", line 161, in detect() File "detect.py", line 16, in detect device = torch_utils.select_device(opt.device) File "/home/ycc/yolov5-master/utils/torch_utils.py", line 33, in select_device assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity AssertionError: CUDA unavailable, invalid device 0 requested

github-actions[bot] commented 4 years ago

Hello @yancccc, thank you for your interest in our work! Please visit our Custom Training Tutorial to get started, and see our Jupyter Notebook Open In Colab, Docker Image, and Google Cloud Quickstart Guide for example environments.

If this is a bug report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom model or data training question, please note that Ultralytics does not provide free personal support. As a leader in vision ML and AI, we do offer professional consulting, from simple expert advice up to delivery of fully customized, end-to-end production solutions for our clients, such as:

For more information please visit https://www.ultralytics.com.

NanoCode012 commented 4 years ago

Check that you have CUDA installed “nvcc -V”

yancccc commented 4 years ago

Check that you have CUDA installed “nvcc -V” The environment is configured, and yolov4 can work normally

yancccc commented 4 years ago

ycc@ycc:~/yolov5-master$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130

glenn-jocher commented 4 years ago

@yancccc it appears you have environment problems. In order to run YOLOv5 correctly your environment must meet the minimum version requirements for the dependencies described in https://github.com/ultralytics/yolov5#requirements. You can either update your local environment to bring it into compliance or you can use one of our verified environment options below.

Reproduce Our Environment

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

dddj969 commented 4 years ago

@yancccc do you solve the problem ? i meet the same problem

XiaoXiLe2023 commented 4 years ago

I meet the same problem. I used: print(torch.cuda.device_count()) print(torch.version.cuda) print(torch.version) print(torch.cuda.is_available()) to check.

got 0 10.2 1.5.1 False

XiaoXiLe2023 commented 4 years ago

ycc@ycc:~/yolov5-master$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130

maybe you can try pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html

rohanbanerjee commented 4 years ago

@Myhuang1996 's solution solved the issue in my case!

DeepAndy commented 4 years ago

try the latest pytorch + correct version of cuda: pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

github-actions[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

caozhiwei1994 commented 4 years ago

Pytorch1.6 supports CUDA 9.2, 10.1 and 10.2. I update the version of CUDA,yolov5 can work.

AxleCode commented 2 years ago

ycc@ycc:~/yolov5-master$ nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2018 NVIDIA Corporation Built on Sat_Aug_25_21:08:01_CDT_2018 Cuda compilation tools, release 10.0, V10.0.130

maybe you can try pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html

PS D:\Kuliah\Yolov5\yolov5-master> nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2022 NVIDIA Corporation Built on Tue_Mar__8_18:36:24_Pacific_Standard_Time_2022 Cuda compilation tools, release 11.6, V11.6.124 Build cuda_11.6.r11.6/compiler.31057947_0

i used cuda 11.6 what version torch and torchvision must im install?

shubhambagwari commented 2 years ago

@DeepAndy

try the latest pytorch + correct version of cuda: pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html

Throwing this error now.

Error:

requirements: torch>=1.7.0 not found and is required by YOLOv5, attempting auto-update...
requirements: 'pip install torch>=1.7.0' skipped (offline)
requirements: torchvision>=0.8.1 not found and is required by YOLOv5, attempting auto-update...
requirements: 'pip install torchvision>=0.8.1' skipped (offline)
YOLOv5  2022-7-20 Python-3.7.6 torch-1.6.0+cu101 CUDA:0 (NVIDIA GeForce GTX 1660 Ti, 6144MiB)

@Myhuang1996 facing the same issue. I tried your solution as well.

glenn-jocher commented 2 years ago

@shubhambagwari you are not meeting requirements and your machine is not online for auto-update to work