FastestDet trains its own data set

 Table of contents

Preface

1. Data set construction

2. Configuration file settings

1..Yaml configuration file introduction

2. Start training

3. Model evaluation

4. Export onnx for testing

Summarize


Preface

Code: https://github.com/dog-qiuqiu/FastestDet

Algorithm introduction: https://zhuanlan.zhihu.com/p/536500269

Training environment: Win11


1. Data set construction

The data set format is the same as Darknet Yolo, and each picture corresponds to a txt tag file. The label format is also based on Darknet Yolo's data set label format: "category cx cy wh", where category is the category subscript, cx, cy are the coordinates of the center point of the normalized label box, and w and h are the coordinates of the normalized label box. Width and height, examples of .txt tag file content are as follows:

2 0.2841796875 0.3815104166666667 0.068359375 0.257825
1 0.43505859375 0.55078125 0.0966796875 0.122395833333333

The data set file structure is as follows:

 

 

 The format of train.txt and val.txt is:

E:\cv_code\FastestDet-main\datasets\images\train\aug_0_10.jpg
E:\cv_code\FastestDet-main\datasets\images\train\aug_0_100.jpg
E:\cv_code\FastestDet-main\datasets\images\train\aug_0_101.jpg

 Code examples to generate train.txt and val.txt:

import os
import glob

# Define the directory containing the dataset
train_dir = r'E:\cv_code\FastestDet-main\datasets\images\train'
val_dir = r'E:\cv_code\FastestDet-main\datasets\images\val'

# Get a list of all file paths in the dataset directory
train_files = glob.glob(os.path.join(train_dir, '*.jpg'))
val_files = glob.glob(os.path.join(val_dir, '*.jpg'))

# Write the file paths to a .txt file
with open('datasets/train.txt', 'w') as file:
    for path in train_files:
        file.write(path + '\n')

with open('datasets/val.txt', 'w') as file:
    for path in val_files:
        file.write(path + '\n')

2. Configuration file settings

1..Yaml configuration file introduction

Take ./configs/coco.yaml as an example:

DATASET:
  TRAIN: 'E:\cv_code\FastestDet-main\datasets\train.txt'       # train.txt
  VAL: 'E:\cv_code\FastestDet-main\datasets\val.txt'           # val.txt
  NAMES: "configs/coco.names"                                  # label name
MODEL:
  NC: 4                                                        # number of classes
  INPUT_WIDTH: 352                                             # input width
  INPUT_HEIGHT: 352                                            # input height
TRAIN:
  LR: 0.001                                                    # learning rate
  THRESH: 0.25                                                 # threshold
  WARMUP: true                                                 # warmup
  BATCH_SIZE: 96                                               # batch size
  END_EPOCH: 10                                                # train epoch
  MILESTIONES:                                                 # Declining learning rate steps
    - 100
    - 200
    - 250

Where coco.names is the label name of your data set

person
bicycle
car
motorbike
.......
toothbrush

2. Start training

The pre-trained model is: shufflenetv2.pth

Specify your configuration file:

        parser.add_argument('--yaml', type=str, default='configs/test.yaml', help='.yaml config')

Start training:

python3 train.py

3. Model evaluation

python3 eval.py --yaml configs/coco.yaml --weight weights/weight_AP05:0.253207_280-epoch.pth

4. Export onnx for testing

python3 test.py --yaml configs/coco.yaml --weight weights/weight_AP05:0.253207_280-epoch.pth --img data/3.jpg --onnx


Summarize:

The above is what I will talk about today. This article only briefly introduces the use of FastestDet. Come on, friends, go practice it.

Guess you like

Origin blog.csdn.net/qq_51511878/article/details/129836906