[YOLO] Unpretentious yolov5 environment configuration

foreword

  Recently, there was a project that required target recognition, so I immediately thought of the famous yolo, so I spent a day understanding it. But unfortunately, an environment I randomly configured can run torch, but as soon as I train the yolov5 library, the computer will blue screen , and then I went to the Internet to find some configuration tutorials, but unfortunately it sounds very impressive, but It feels like most of it is crap, inefficient and not accurate enough. So I decided to make a tutorial based on my own experience.

Preparation

  This article assumes that the reader already has a python environment (conda is also available) , and understands some basic python knowledge, such as package management. If not, it is recommended to close this tutorial directly or read it after setting up the python environment.

PyTorch installation

reference link

  Although the construction of the PyTorch environment sounds complicated, it is not difficult to operate it by hand. In summary, it is three steps: install cuda, install cudann, pip install torch related packages

  Regarding the relationship between cuda, cudann and pytorch, refer to this tutorial . My understanding is that cuda is a workbench that provides underlying gpu computing functions; and cudann is a tool on the workbench that uses the underlying functions of cuda to implement neural networks. The basic model; pytorch is more like a more advanced device made with tools on the workbench. It relies on cuda and cudann, but it is more convenient to use and makes the process of calling gpu calculations to achieve deep learning easier.

  The concept part is over, now let's start the practical operation. Most of the online tutorials in this part are step-by-step, that is, first install cuda, then cudann, and then pytorch. This is because many people feel that it is necessary to find a cuda version that is compatible with their graphics card driver version. but! In fact, you can also choose to install the driver during the cuda installation process, which means that the cuda installation can help you install the corresponding driver that adapts to this version of cuda. nvidia-smiMoreover, the Cuda Version and the version in the NVIDIA control panel viewed using the command are not the so-called "highest supported version", but the driver version installed on the computer at this time. You can download a driver update program from the NVIDIA official website to update . Then someone will definitely ask, can a new version of the driver be installed even if the graphics card model is older? Judging from the driver provided by the official website, it should be no problem. The new version of the driver is very compatible with the hardware. If you are not at ease, you can check the driver model supported by the graphics card model in your computer in this link . Here we take a driver updated on 2023.5.2 (10 days before the release date) as an example, as shown in the figure below.

insert image description here
It can be seen that there are still many supported models.

  Compared with the graphics card driver model on the adapter computer, I think the cuda version selection should refer to the version of the pytorch package, and this is why I recommend installing pytorch first, that is, first determine the pytorch version, and then go to Download the compatible cuda version.

  • 1 The step of installing pytorch
    is very simple, go directly to the official website , copy the following line of command and execute it in the terminal. [It is recommended to get the latest version if there is no special requirement]

insert image description here

This bag is a bit big, you need to bear with it. If you don’t want to bear it, find out how to change the source of pip (or change the source of conda)

  • 2 Install cuda
    After installing pytorch, go to the NVIDIA official website to find the cuda version corresponding to the above torch, and then download and install it. The specific process will not be demonstrated, and the next step can be done without thinking. Emphasize the middle points:
    insert image description here
    insert image description here
    insert image description here

    check whether the installation is successful nvcc --version:
    insert image description here

  • 3 Installing cudann
    is even easier. Also go to the NVIDIA official website to download the corresponding version of the compressed package, and then put the decompressed file in the cuda installation path. There should be a folder merge operation.

    Verify that the installation was successful:
    insert image description here

yolov5

  yolov5 can be understood as a python-based project, but this project needs to rely on the previously configured pytorch environment, so you have to configure the environment first (actually, install the pytorch package and its dependent packages). For the rest of the development process, you only need to look at the official website—that is, the GitHub link .

yolov5 project structure

  As shown in the figure below, this is the release source code of the latest version 7.0 of yolov5:

insert image description here

  • classifyThe folder is the training and verification code corresponding to image classification, for example, it can be used to classify whether a face is wearing a mask, etc.
  • dataThe folder mainly contains data for training, mainly yaml files (which can be understood as configuration files during the training model process, mainly indicating the folder where the training data is located and the target category)

insert image description here

insert image description here

The development process is updated along with the situation

problems encountered

  As soon as I ran the train.py file, the computer got a blue screen. At that time, I thought it was because the cuda version was too high for my graphics card, but then I tried to reinstall a 11.8 version of cuda, which corresponds to my pytorch version. I didn’t expect it Just fine, so I think that the adaptation of the cuda version and the pytorch version is the most important.

follow-up tutorial

Guess you like

Origin blog.csdn.net/ZHOU_YONG915/article/details/130651567