When running yolov5, run the script after installing pytorch
import torch
a=torch.cuda.is_available()
print(torch.__version__)
print(a)
An error occurred:
UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment,
e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero.
(Triggered internally at /opt/conda/conda-bld/pytorch_1623448255797/work/c10/cuda/CUDAFunctions.cpp:115.)
return torch._C._cuda_getDeviceCount() > 0
First, check whether the versions of the graphics card driver, CUDA, cudnn and pytorch match. If not, uninstall and reinstall the corresponding version.
CUDA10.2 Python3.8 pytorch1.8 no mistake.
If the versions are correct, you need to set the environment variable and enter sudo vim ~/.bashrc
, add at the end:
# The first three lines are required when installing CUDA
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export CUDA_HOME=/usr/local/cuda/bin
export CUDA_VISIBLE_DEVICES=0
Save and exit. Try whether you can use CUDA.
If not, enter apt-get install NVIDIA-modprobe
, and there should be no problem.
It will be OK when you installed apt-get install NVIDIA-modprobe
Read More:
- [Solved] UserWarning: CUDA initialization: CUDA unknown error
- [Solved] NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL ,unhandled cuda error, NCCLversion 2.7.8
- Pytorch failed to specify GPU resolution
- [Solved] RuntimeError: CUDA error: out of memory
- Cuda Runtime error (38) : no CUDA-capable device is detected
- CUDA_ERROR_SYSTEM_DRIVER_MISMATCH [How to Solve]
- [Solved] CUDA fails to compile in visual studio and throws error msb3721 and nvcc fatal
- PyCharm Error: RuntimeError: CUDA out of memory [How to Solve]
- How to Solve error: command ‘C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin\nvcc.exe‘ failed
- Pytorch error: `module ‘torch‘ has no attribute ‘__version___‘`
- [Solved] volatile was removed and now has no effect. Use `with torch.no_grad():` instead.
- [Solved] Pytorch loading model specified GPU card number error or failed to specify
- Error 1 error MSB3721: Command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe” -genco
- [Solved] Pip install icu failed: Command “python setup.py egg_info” failed with error code 1 in
- [Solved] RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR
- Cocoapods Install ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension.
- [Solved] The method getContextPath() from the type HttpServletRequest refers to the missing type String
- Yolox_s.pth Convert to tensorRT Error: AttributeError: ‘tensorrt.tensorrt.Builder‘ object has no attribute ‘max_workspace_size‘
- DM Install Error: error while loading shared libraries: libdmnsort.so:
- [Solved] New MAC Unity Develop Error: error installing cocoapods