Error: Torch not compiled with CUDA enabled It is enough to read this article

 

Table of contents

1. CUDA download and installation steps

2. Configuration of Pytorch environment

The author's Computer Vision Research 0 has just entered as a Research 1. Recently, the YOLO series in the learning target detection algorithm. When running the YOLO V1 training code, this error is reported

The reason is simple: CUDA and Torch versions are not compatible

When encountering such problems, first check the CUDA support version of the computer:

  Open cmd, enter

nvidia-smi

You can see that in the red box is the highest version of cuda supported by the computer. When we download from the official website, just download this version or below (it is recommended to download this version or below)

Second, check the version of CUDA in your computer (check if CUDA is installed):

     Open cmd, enter

nvcc --version

You can see that my initial installation version is 11.7

If it is displayed that nvcc cannot be found, it means that CUDA is not installed in the computer.

  Replenish:

  If you have CUDA in your computer but the version is not suitable, just delete and reinstall. It should be noted that it must be uninstalled cleanly. I uninstalled it in the control panel that comes with the computer: click Control Panel - Programs - Programs and Features

Find all uninstalls related to NVIDIA, and then go to the software housekeeper to clean up the uninstall residue. Other uninstall methods are also available, but must be uninstalled cleanly.

1. CUDA download and installation steps

        If the computer supports CUDA11.x, it is better to download version 11.3, which is safer.

        Click on CUDA official website: https://developer.nvidia.com/cuda-downloads

        Select more previous versions:

 Choose the appropriate one according to your computer system to download:

 I put it in the F drive:

 After the installation package is downloaded, right-click—administrator run—enter the installation, and click the next step without thinking (try to install according to the installation path selected by the system for you, which is the path of the C drive. I tried to install it on other disks before. In the installation, there is no success), need to pay attention: in the "installation options" column select: custom installation.

 After the installation is complete, check whether the installation is successful, open cmd again, and enter

nvcc --version

 

You can see that my current version has changed to 11.3, indicating that the installation was successful.

2. Configuration of Pytorch environment

    First, compare the corresponding versions of CUDA and pyTorch. You can see that there are three pytorch versions corresponding to CUDA. Here I choose 1.11.0

 

 After selecting the version, we will start to download the pytorch installation package.

  There are two methods:

                    1. On the pytorch official website: https://pytorch.org/get-started/locally/ choose online installation:

 However, such an installation method requires an excellent network environment, and the error rate in the middle process is high. I used the second method, offline download.

                    2. Offline installation: http://2.https://download.pytorch.org/whl/torch_stable.html

Just select the corresponding version, where cu: cuda version; cp: Python version; torch: torch version, choose the system that suits you, and click the link to download.

 After Torch is downloaded, install it offline:

Open Anaconda

Switch the installation path: directly copying the path cannot be cut (you need to enter cd to switch the path)

 Need to enter directly on this basis:

F:

Press Enter to go to the F drive path

 We need to install torch under this path. Enter at the command line

pip install torch

Add a Tab key to export the torch installation link, and add the mirror source of Tsinghua University: https://pypi.tuna.tsinghua.edu.cn/simple/ to speed up the installation

If an error is reported:

It shows that pip needs to be updated, you can directly enter in cmd:

python -m pip install --upgrade pip

just update

 Then wait for the installation of torch, if the display is successful, the installation is complete

 

After the installation is complete, we can perform a simple version test:

Enter in anaconda:

import torch

print(torch.__version__):查看torch版本

print(torch.cuda.is_available()):看安装好的torch和cuda能不能用,也就是看GPU能不能用

Return as shown in the figure below, which means the installation is successful

 Back in the train training script, run the code:

 Bugs resolved!

I hope it can help everyone~~

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_72056722/article/details/126651703