I want to train my dataset with YOLO in Jupyter Notebook and I need to use the GPU. I am encountering errors while training the model.
code:
model.train(data=data_config_path, epochs=5, optimizer='Adam', batch=8, imgsz=640,lr0=0.01, device=0)
error:
ValueError: Invalid CUDA 'device=0' requested. Use 'device=cpu' or pass valid CUDA device(s) if available, i.e. 'device=0' or 'device=0,1,2,3' for Multi-GPU.
torch.cuda.is_available(): False
torch.cuda.device_count(): 0
os.environ['CUDA_VISIBLE_DEVICES']: None
Seehttps://pytorch.org/get-started/locally/ for up-to-date torch install instructions if no CUDA devices are seen by torch.
To solve the problem:
I downloaded and installed the CUDA Toolkit 11.8 Downloads* exe file.
-
From the PyTorch website**, I ran the installation command:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
. -
From the CUDNN web site***, I downloaded the cuDNN, Windows zip file and copied the bin, include, and lib folders from the zip file to the respective folders in “C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.8”.
Additionally, I added the following paths to the environment variables:
-
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.8bin
-
C:Program FilesNVIDIA GPU Computing ToolkitCUDAv11.8libnvvp
Now, when I check the version information in the terminal using nvcc --version
, it shows the correct version information.
import torch
print(torch.cuda.is_available())
print(torch.cuda.device_count())
print(torch.version.cuda)
When I run the following commands in PowerShell:
- I get the results
True
,1
,11.8
respectively.
However, when I run these same commands in Jupyter Notebook,
I get False
, 0
, None
.
I couldn’t figure out why I get True
in PowerShell but False
in Jupyter Notebook.
*(https://developer.nvidia.com/cuda-11-8-0-download-archive)
**(https://pytorch.org/get-started/locally/ )
***(https://developer.nvidia.com/rdp/cudnn-archive)
****”Download cuDNN v8.9.7 (December 5th, 2023), for CUDA 11.x”
I want to train my dataset with YOLO in Jupyter Notebook
mrNR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.