Yolov5: AssertionError: CUDA unavailable, invalid device 0 requested

Created on 22 Jul 2020  ·  12Comments  ·  Source: ultralytics/yolov5

~/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

Stale question

Most helpful comment

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

All 12 comments

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:

  • Cloud-based AI systems operating on hundreds of HD video streams in realtime.
  • Edge AI integrated into custom iOS and Android apps for realtime 30 FPS video inference.
  • Custom data training, hyperparameter evolution, and model exportation to any destination.

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

Check that you have CUDA installed
“nvcc -V”

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

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

@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):

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

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

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

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

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings