Configure GPU training environment (Anaconda) in pycharm (yolov5)

Table of Contents

1. Specific configuration process:

2. Create a virtual environment at the specified location (path):

3. Commonly used conda commands:

4: Some problems encountered when running the model:

4.1: conda added python interpreter cannot find the corresponding python.exe file

4.2: Error “OSError: [WinError 1455] The page file is too small and the operation cannot be completed.”

4.3: Error “CUDA out of memory. Tried to allocate 14.00 MiB”

5: Causes and solutions of NAN problems in CUDA11.1 version:

6: The difference between CUDA in the virtual environment and CUDA in the system:

7: For anime characters, the training effect is not very good:


1. Specific configuration process:

Teach you step by step how to install Anaconda and configure virtual environment yolov5

2. Create a virtual environment at the specified location (path):

1: Use the command to view the currently owned virtual environment

conda info --envs


2: Create a new virtual environment in the specified directory and enter the command:

conda create --prefix=C:/ProgramData/Anaconda3/envs/pytorch python=3.8

Among them, C:/ProgramData/Anaconda3/envs is the location of the created directory; /pytorch is the name of the created environment and python=3.8 is the created version of python.

As you can see, the verification is indeed created where we want it to be

OK, created successfully:

3. Common conda commands:

Comprehensive list of commonly used commands

  • The code to delete the virtual environment is as follows (yolo5 represents the env name)
conda env remove -n yolo5
  • Activate virtual environment
conda activate F:\Anaconda\envs\yolo5

4: Some problems encountered when running the model:

4.1: conda adds python interpreter and cannot find the corresponding python.exe file

There are many solutions on the Internet, I referred to this: (It is also trained with GPU. If the interpreter is python in the anaconda virtual environment, the effect should be the same)

  • Just find python.exe in conda’s virtual environment in Virtualenv Enviroment.
  • Just find the conda virtual environment directly in System Environment

4.2: Error “OSError: [WinError 1455] The page file is too small and the operation cannot be completed.”

This seems to be related to the virtual memory allocated to the disk where the cuda virtual environment is located:

For details, please refer to the following blog:

The page file is too small to complete the operation.

4.3: Error “CUDA out of memory. Tried to allocate 14.00 MiB

This should be because the batch-size set for the trained model is too large, and the GPU memory cannot satisfy it.

Adjust the batch-size smaller, such as setting the commonly used 256 128 64 32 16, etc. I changed the 16 in yolov5 to 8, and then the problem was solved.

Finally, attach a screenshot of the successful training of the yolov5 model using GPU:

(It took 2 hours to run the same size data set on the CPU before, but only 16 minutes on the GPU. I have to say it’s really delicious)

Graphics card configuration: (If you have money, you will definitely get a better one)

5: Causes and solutions for NAN problems in CUDA11.1 version:

After I completed the above steps, some errors occurred, specifically in the following form:

The reason for this problem is that the CUDA version is higher (11.1). It is best to use the 10.2 CUDA version. You only need to install the 10.2 cuda in the virtual environment and do not need to reinstall it in the system.

For solutions, please refer to the following blog:

When YOLOv5s GTX 1660 Ti is trained, the problem occurs that box, obj, and cla are all nan. P, R, and mAP are all 0. The versions of Pytorch, cuda, and cudnn are incorrect.

NAN problem occurs in yolov5 training results of GTX 16XX series graphics card

Solution to the problem that yolov5 cannot detect the target after training its own data set

In addition, it may also be caused by the following problems:

The yolov5 data set trained on the server cannot detect anything on my computer (solved)

6: The difference between cuda in the virtual environment and cuda in the system:

What is the impact of the difference between the cuda version in the virtual environment and the system cuda version?

7: For anime characters, the training effect is not very good :

Originally I wanted to train a model that automatically recognizes anime characters (Nine Pillars) in videos, but I did a small experiment with the Love Pillar – Kanroji Mitsuri and the Water Pillar – Tomioka Giyu (40 pictures each were selected, of which 3 Zhang as the verification set), in the case of batch_size=8 and epoch=200, in the end it can only recognize these two characters without much problem, but if you feed it a cat or dog or other columns, it may recognize errors. (It may be because the data set is too small, and it is also difficult to identify the anime characters themselves)

If you have an open source Demon Slayer data set, you can consider sharing it with bz, hehe; if you have any questions, please leave a message in the comment area!

The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. Python entry skill treePreparatory knowledgeCommon development tools 385545 people are learning the system