YOLOv8 common error collection (ModuleNotFoundError, NameError, KeyError, nan value and map are all 0,? CUDA out of memory, [WinError 145?]

Table of Contents

1.ModuleNotFoundError: No module named ultralytics +

Solution:

2.KeyError: ‘GAM_Attention’

2.1 Reasons

2.2 Solutions

3.NameError: name ‘GAM’ is not defined

3.1 Reasons

3.2 Solutions

4. Loss has nan values during training or P\R\map all have 0 values during testing.

4.1 Reason one:

4.2 Reason two

4.3 Reason three

4.4 Reason four

A big pitfall for GTX16xx users. Basically every GTX16xx user will encounter these problems when using the YOLO series algorithms.

5.[WinError 1455] The page file is too small and the operation cannot be completed.

5.1 Reasons

5.2 Solution

6.RuntimeError: CUDA out of memory

6.1 Reasons

6.2 Solution


1.ModuleNotFoundError: No module named ultralytics +

Solution:

Add the following code to the front of train.py

import sys
sys.path.append("/home/shares/myproj/other_tasks/yolov8/")
# That is the absolute path where the ultralytics folder is located

After execution, an error is reported. There is no ultralytics module in task.py. Also add the above code before task.py.

If the error still occurs after execution, just add the code before the error code.

2.KeyError: ‘GAM_Attention’

When we add some attention mechanisms to yolov8 and improve the network structure, we often encounter Key Error reports.

2.1 reason

Used pip install ultralytics

2.2 solution

Open the terminal of pycharm, which is the bottom line

choose this one

Uninstall pip uninstall ultralytics

Run python setup.py install.

Don’t worry about what happens in the middle

How to judge whether the installation is successful mainly depends on whether the final output contains Finished processing dependencies for ultralytics.

In this way, you can run it according to your own modified model.

3.NameError: name ‘GAM’ is not defined

3.1 reason

An error occurred during module registration

3.2 solution

Add module to conv

Register and reference in init and task

Fill in the calling method

Configure yaml file

# Ultralytics YOLO , GPL-3.0 license
# YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect

#Parameters
nc: 80 # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8-SPPCSPC.yaml with scale 'n'
  # [depth, width, max_channels]
  n: [0.33, 0.25, 1024] # YOLOv8n summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs
  s: [0.33, 0.50, 1024] # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients, 28.8 GFLOPs
  m: [0.67, 0.75, 768] # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients, 79.3 GFLOPs
  l: [1.00, 1.00, 512] # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
  x: [1.00, 1.25, 512] # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs

# YOLOv8.0n backbone
backbone:
  # [from, repeats, module, args]
  - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2
  - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4
  - [-1, 3, C2f, [128, True]]
  - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8
  - [-1, 6, C2f, [256, True]]
  - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16
  - [-1, 6, C2f, [512, True]]
  - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32
  - [-1, 3, C2f, [1024, True]]
  - [-1, 3, GAM_Attention, [1024]]
  - [-1, 1, SPPF, [1024, 5]] # 10

# YOLOv8.0n head
head:
  - [-1, 1, nn.Upsample, [None, 2, 'nearest']]
  - [[-1, 6], 1, Concat, [1]] # cat backbone P4
  - [-1, 3, C2f, [512]] # 13

  - [-1, 1, nn.Upsample, [None, 2, 'nearest']]
  - [[-1, 4], 1, Concat, [1]] # cat backbone P3
  - [-1, 3, C2f, [256]] # 16 (P3/8-small)

  - [-1, 1, Conv, [256, 3, 2]]
  - [[-1, 13], 1, Concat, [1]] # cat head P4
  - [-1, 3, C2f, [512]] # 19 (P4/16-medium)

  - [-1, 1, Conv, [512, 3, 2]]
  - [[-1, 10], 1, Concat, [1]] # cat head P5
  - [-1, 3, C2f, [1024]] # 22 (P5/32-large)

  - [[16, 19, 22], 1, Detect, [nc]] # Detect(P3, P4, P5)

4. During training, loss appears with nan values, or during testing, P\R\map is all 0 values

4.1 Reason One:

Dataset issues

Solution:

The data set labels and pictures do not match, or there is Chinese in the data set txt file.

4.2 Reason Two

batchsize setting problem

Solution:

The batchsize setting is at the critical position of the computer’s video memory, and the running process is unstable. There may be no problems in the early stage, but the map will appear later.

0 case

4.3 Reason Three

Environment configuration issues

Solution:

It is recommended to reconfigure as follows

YOLOV8 builds a target detection system from scratch (a must-read for modifying the model structure) with an industrial defect detection data set_Chen Ziyi’s blog-CSDN blog

4.4 Reason Four

A big pitfall for GTX16xx users. Basically every GTX16xx user uses the YOLO series of algorithms. , will encounter these problems.

Solution:

There is no way, the only solution is to use the configuration of cuda10.2

CUDA 10.2
pip install torch==1.12.0 + cu102 torchvision==0.13.0 + cu102 –extra-index-url https://download.pytorch.org/whl/cu102

The training speed may be a little slower, but it can still be used, and it is effective in personal testing.

5.[WinError 1455] The page file is too small to complete the operation

5.1 reason

Insufficient virtual memory.

5.2 solution

In line 81 of datasets under the utils file, change workers=nw to =0:

6.RuntimeError: CUDA out of memory

6.1 Reason

The graphics card does not have enough memory

6.2 Solution

This problem lies in the gpu memory. Just change the batch size to a smaller size and it will be fine.