YOLOV8 builds a target detection system from scratch (a must-read for modifying the model structure) and comes with an industrial defect detection data set

Table of contents

1.YOLOV8 introduction

2.YOLOV8 installation

2.1 Environment configuration

3. Dataset preparation


1.YOLOV8 introduction

Yolov8 structure diagram: 

YoloV8相对于YoloV5的改进点:
Replace the C3 module with the C2f module.
Replace the first 6x6 Conv with 3x3 Conv in the Backbone.
Delete two Convs (No.10 and No.14 in the YOLOv5 config).
Replace the first 1x1 Conv with 3x3 Conv in the Bottleneck.
Use decoupled head and delete the objectness branch.
anchor free.
 

YoloV8 accuracy comparison: 

 

2.YOLOV8 installation

If it is just for simple use, just read the following article.

YOLOv8 nanny-level tutorial (training your own data set)_Chen Ziyi's blog-CSDN blog

If you want to change the structure of the model, continue reading below.

2.1 Environment configuration

First, it is recommended to use anaconda to configure the python environment. If you don’t know how, read the following blog

The latest Anaconda installation-nanny-level tutorial_Chen Ziyi's blog-CSDN blog

conda create -n YOLOv8 python=3.8  #创建YOLOv8的环境
 
conda activate YOLOv8   #激活环境
 
 

Install pytorch

CUDA 11.6
pip install torch==1.12.0+cu116 torchvision==0.13.0+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 -i https://pypi.tuna.tsinghua.edu.cn/simple
CUDA 11.3
pip install torch==1.12.0+cu113 torchvision==0.13.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113 -i https://pypi.tuna.tsinghua.edu.cn/simple

     Choose one   

Install dependency packages

pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple/

Open pycharm and load your environment.

 

 Select your python version, and the normally newly created conda interpreter will pop up automatically.

Next, open the terminal of pycharm, which is the bottom line.

choose this one 

If you have installed the ultralytics package, please uninstall it. If not, skip this step.

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.

3. Dataset preparation

Link: https://pan.baidu.com/s/1FaBTUQvceUJJu3s1dg4xMg 
Extraction code: ypwa

We have prepared a steel data set for everyone.

put data.yaml in the following path

 The data set can be placed in the following path

 Modify the address in yaml

 Create a my train file

 Put the following code

from ultralytics import YOLO

# model = YOLO('yolov8n-CF2_ATT.yaml')
# model.train(data='data.yaml', epochs=5)

model = YOLO('yolov8n.yaml')
model.train(data='data.yaml', epochs=10)

 The parameters of the model.train function are selected below

 After configuration, you can train. You can also modify the model configuration file according to your needs.

View Results

Configure my val

from ultralytics import YOLO

model = YOLO(r'D:\YOLOv8\ultralytics\models\yolo\detect\runs\detect\train11\weights\best.pt')
# It'll use the data yaml file in model.pt if you don't set data.
model.val()
# or you can set the data you want to val
model.val(data='data.yaml')

 The above is the complete process

The next article will list the errors that yolov8 may encounter.

Guess you like

Origin blog.csdn.net/weixin_45303602/article/details/132767807