YOLOv8 trains your own data set and learns it in ten seconds! Xiaobai Yiwen learns the whole process of YOLOv8 training! Adapt to Xiaobai

Tip: After the article is written, the table of contents can be automatically generated. For how to generate it, please refer to the help document on the right.

YOLOv8 training, suitable for novice training, novice YOLOv8 training on their own data set tutorial! Super simple and super detailed! !


1. COCO article data set training (annotated text format is text)

Four steps of training, master it and run!


1.1. YOLOv8 deep learning environment construction and installation

1.1.1 Detailed environment configuration

My graphics card configuration is: RTX A4000 (16GB)
. Specific environment:
PyTorch 1.8.1
Python 3.8 (ubuntu18.04)
Cuda 11.1
dependent libraries can be installed according to the requirements.txt file.

1.1.2 Install the ultralytics library required by YOLOv8

Install the ultralytics library required by YOLOv8. In the 1.1.1 environment, execute the following code:

pip install ultralytics

1.1.3 Download YOLOv8 code package

Download the YOLOv8 code package to this environment, and the execution code is as follows:

git clone https://github.com/ultralytics/ultralytics.git

Automatic download
At this point, the environment setup is completed!

1.2. Prepare your own data set

1.2.1 Data set creation in coco format (relatively simple, suitable for novices)

The contents of the folder are as follows:

------coco (Folder name can be chosen casually, cannot contain Chinese characters)
---------images
------------train (storage training set images)
-- ----------test (storage test set images)
------------val (storage verification set images)
---------tables
---- --------train (storage of training set annotation files)
------------test (storage of training set annotation files)
------------val ( Store training set annotation files)

1.2.2 Create a new training execution simple code

In the YOLOv8 package, create a new train.py with the following code:

from ultralytics import YOLO
 
# Load a model
# yaml会自动下载
model = YOLO("ultralytics/cfg/models/v8/yolov8ContextAggregation.yaml")  # build a new model from scratch
#model = YOLO("d:/Data/yolov8s.pt")  # load a pretrained model (recommended for training)
 
# Train the model
results = model.train(data="coco128.yaml", epochs=100, imgsz=640)

The storage location of this code in the YOLOv8 package is shown below:
Insert image description here

1.2.3 Execute training instructions and automatically configure weights and original data sets

In the configured environment, execute the training instructions as follows,

python train

Then automatically download the original data set and weights. Just wait for the download to complete.

1.3 Replace the original data set with your own data set (for details, please follow Station B: AI Academic Calling Beast)

1.3.1 Find the original data set, delete it, upload your own data set, and rename it to coco128 (the name of the original data set)

1.3.2 Modify the name and category in the coco128.yaml file

Path: ultralytics/ultralytics/cfg/datasets/coco128.yaml.
Just modify it accordingly. If you don’t know how to modify it, just read the path modification tutorial in 1.5 of this article!

1.4 Train your own data set

Execute the training command again:

python train

You can complete your own data set training.

1.5 Tutorial on modifying path of yaml file (important! People must learn it!)

1.5.1 Error reporting situation

Dear friends, when training data sets and improving models, we often encounter path modifications, resulting in errors. I’m going to explain it here, I hope it can help all the fans!
For example, the error encountered in the picture below:
Insert image description here
namely:

FileNotFoundError: 'ultralytics/cfg/models/v8/yolov81ContextAggregation.yaml' does not exist

Similar errors are generally path problems.

1.5.2 Error handling

For example: 1. Model network configuration file:
Read the path: ultralytics/cfg/models/v8/yolov8ContextAggregation.yaml
Its meaning is: YOLOv8yolov8ContextAggregation.yam file in v8 in the models file in the cfg file under the ultralytics file
2. Data set path file

ultralytics/ultralytics/cfg/datasets/coco128.yaml

Open the file and find the path configuration, as follows:

path: ../datasets/coco128  # dataset root dir
train: images/train2017  # train images (relative to 'path') 128 images
val: images/train2017  # val images (relative to 'path') 128 images
test:  # test images (optional)

The path indicates that the path of train under the coco128 folder in the datasets file in the root directory
is the train2017 folder in the images file
. Others are similar.
Just add, reduce the path or modify the name corresponding to your own data or file path.

Summarize

For novices, text tutorials always seem pale and ineffective, so I uploaded relevant video explanations on station B. Please follow the blogger at Bilibili: AI Academic Calling Beast.
More SCI writing skills and innovations, as well as YOLO model improvement source code and other resources, are all uploaded at Bilibili. Click on the blogger's homepage, in the workshop!

Guess you like

Origin blog.csdn.net/weixin_51692073/article/details/132642253