yolov5 GPU running environment construction (not detailed version)

The computer has been reinstalled recently, so I took some notes on environment construction for easy reference later.

Install anaconda

There is a record here, skip it.

anaconda can create different virtual environments and install different python versions. I have created a new virtual environment here specifically to run yolov5.

Configure GPU and pytorch

CUDA (Compute Unified Device Architecture) is a parallel computing platform and programming model launched by graphics card manufacturer NVIDIA in 2007.
Pytorch is the python version of torch, a neural network framework open sourced by Facebook, specifically designed for GPU-accelerated deep neural network (DNN) programming.

// A quick aside here, it seems that there is no need to download CUDA, it seems that downloading pytorch will come with it.

Install nvidia driver

Official website: https://www.nvidia.cn/geforce/drivers/, enter the installation and download.

Install pytorch

Check the CUDA version:
Command line input: nvidia-smi, there will be a CUDA Version, remember it.
Go to the official website and select the corresponding command to download. My version is CUDA 11.6, so I use this one.
Insert image description here

-c pytorch -c nvidia can be omitted, which means downloading from pytorch and nvidia. If not, the domestic mirror source you configured will be used to download, but I had some problems using the domestic mirror source, and the download speed of using foreign sources It's not too slow, so I just use the official command.

test

Open the command line and enter the python environment you configured (the default is the base environment). Enter python and you will enter python interactive mode. Here you need to write python code instead of cmd command. Enter the following code.

import torch    # 导入torch 
print(torch.cuda.is_available())    # 检验是否可以使用GPU
print(torch.__version__)        #输出torch版本

If everything runs normally and the output results are what you want, pytorch is basically installed successfully.

Install dependency packages

Enter the yolov5 directory, open the command line, and enter pip install -r requirements.txtthe required modules to install.

Download pre-trained weights

Pretrained models are models trained on large benchmark datasets to solve similar problems.
Since training such a model is computationally expensive, it is common practice to import published results and use the corresponding model. When training a target detection model, you can use the pre-trained weights of these neural networks to initialize the parameters of the backbone, so that more effective features can be extracted at the beginning, that is, not starting from 0.
This can increase speed on the one hand and accuracy on the other.
Download address: https://github.com/ultralytics/yolov5/releases
Scroll down, and under Assets, download .ptthe file ending with (different models are released under different versions, and you may be able to judge these weights based on the file size Effect)
Insert image description here

detect

Now that the configuration is almost complete, you can run detect to check it.

Open detect.pythe file and set the parameters in about 200 lines.
– weights: training weights
– source: the picture to be predicted
– data: data set configuration file
Insert image description here

Run detect.pythe file, where the data set will be downloaded online and wait for the program to finish...

(You can also check the download address in the corresponding .yamlfile, download it yourself, and allocate the folder storage directory as required.)

The terminal will display the path to save the running results (starting from yolov5 as the root directory).
For example, this is my directory:
Results saved to runs\detect\exp1
the coco128 training set is used by default, and there are 80 categories marked in it.
Insert image description here

Guess you like

Origin blog.csdn.net/m0_67313306/article/details/128179039