当前位置:网站首页>Mmdetection uses yolox to train its own coco data set
Mmdetection uses yolox to train its own coco data set
2022-06-27 02:16:00 【Ten thousand miles' journey to】
yolox As the strongest target detection algorithm on the current surface , use yolox You can get twice the result with half the effort . However ,mmdetection Training yolox The configuration file is written in the same way as faster-rcnn Some are different , If you directly apply faster-rcnn There will be multiple exceptions in the configuration file of . And it is difficult to find on the Internet mmdetection use yolox Training coco Cases of datasets , For this reason, bloggers have practiced for many times , It's finally done yolox Training for , And found out yolox And faster-rcnn The configuration files are written differently .
Bloggers found yolox And faster-rcnn There are the following differences in the configuration file of :1. When modifying the output of the model class It's different 、2. There are differences in the way data sets are set up 、3. stay lr_config The setting method is different 、4. Set input data size Different ways . Write a blog to share your experience , complete yolox The training configuration code is at the end of the blog .
1、num_classes The difference between settings
faster-rcnn:
model = dict(
roi_head=dict(bbox_head=dict(num_classes=len(classes))))
yolox:
model = dict(
#roi_head=dict(bbox_head=dict(num_classes=len(classes))))
bbox_head=dict(type='YOLOXHead', num_classes=len(classes)))
use faster-rcnn How to set yolox The following error will be reported in the output header of

2、 There are differences in the way data sets are set up
although yolox And faster-rcnn For both settings coco Data sets are trained , however yolox Of config The training data will be datatype Adjusted for MultiImageMixDataset, See the following figure for details

In the same configuration , As shown in the figure below .faster-rcnn You can train the model normally , and yolox Will save , Tips FileNotFoundError: CocoDataset: [Errno 2] No such file or directory: 'data/coco/annotations/instances_train2017.json'.

This is because yolox Of train daset One more dataset object , So you need to dataset Set it up , And to train dataset Of type Adjusted for MultiImageMixDataset. therefore , stay yolox The data settings in should be adjusted according to the following format .
data = dict(
samples_per_gpu=1, # batch size
workers_per_gpu=1, # num_workers
train=dict(
type='MultiImageMixDataset',
dataset=dict(
type='CocoDataset',
ann_file='data/voc07_train.json',
img_prefix=data_root,
classes=classes,
filter_empty_gt=False),
),
val=dict(
img_prefix=data_root,
classes=classes,
ann_file='data/voc07_val.json'),
test=dict(
img_prefix=data_root,
classes=classes,
ann_file='data/voc07_test.json'))
3、lr_config The difference between settings
At first, bloggers thought yolox The learning rate scheduling method should be able to work with faster-rcnn General purpose , The results were unexpected .faster-rcnn And yolox The supported learning rate scheduling methods are different .
faster-rcnn The default scheduler :
lr_config = dict(
policy='step',
warmup='linear',
warmup_iters=500,
warmup_ratio=0.001,
step=[7])
yolox Default learning rate scheduler :
lr_config = dict(
_delete_=True,
policy='YOLOX',
warmup='exp',
by_epoch=False,
warmup_by_epoch=True,
warmup_ratio=1,
warmup_iters=5, # 5 epoch
num_last_epochs=10,
min_lr_ratio=0.05)
If yolox Use faster-rcnn Learning rate scheduler , Because config The following error will be reported for the inheritance relationship of . because yolox Default learning rate scheduler (policy=‘YOLOX’) in num_last_epochs Parameters , and faster-rcnn The default scheduler (policy=‘step’) The parameter does not exist in .

4、 Set data entry size The difference between
faster-rcnn The image does not exist in the model configuration file of size Setting parameters of , By setting configs\_base_\datasets\coco_detection.py Medium size To control the input image size, See the specific figure 5

However , stay yolox in , The configuration file of the model is pipeline Adjustments made , Set the... Of the input data size Need to configs\yolox\yolox_s_8x8_300e_coco.py Set in

5、 complete yolox Training profile
The complete training profile is shown below , The data set of bloggers here is only shoot A category , The blogger's picture path is ‘D:/AI match / Citrus flower and Fruit Shoot recognition based on visible light image ’ Next , and coco The data is in mmdetection Of data Next . Because the blogger's coco The data is from voc From data conversion , For data set conversion methods, please refer to Chapter 1 of the following links , The configuration file is written according to this blog .mmdetection2 The use of tutorials from data processing 、 Profiles to training and testing ( Support coco Data and pascal_voc data )_ A flash of hope to my blog -CSDN Blog _mmdetection2 This paper mainly describes mmdetection Training and testing of , Take data processing as the starting point , To dataset partition 、 Dataset conversion 、 Configuration file writing 、 Model training and testing and use . because mmdetection2 The default data format is coco Format , and labelimg The generated annotation file is xml( Closest to voc data ), To this end, the coco Based on the data set . We can use mmdetection The data conversion method in will pascal_voc The data set is converted to coco Data sets , So as to realize the right to coco Data and pascal_voc Data support .pascal_voc The data set is converted to coco Before data set, you should pay attention to , Be sure to divide the data set first (https://hpg123.blog.csdn.net/article/details/124617894
# This new configuration file inherits from an original configuration file , Just highlight the necessary modifications
_base_ = './configs/yolox/yolox_s_8x8_300e_coco.py'
#1、 Modify dataset related settings ----------
# Dataset type
dataset_type = 'COCODataset'
#label value
classes = ('shoot',)
#2、 Set training super parameters ----------
# Modify the number of model classifications
model = dict(
#roi_head=dict(bbox_head=dict(num_classes=len(classes))))
bbox_head=dict(type='YOLOXHead', num_classes=len(classes)))
# Pre training weights to load
#load_from="./work_dirs/faster_rcnn_r50_fpn_1x_coco/epoch_12.pth"
# Trained epcoh Count
runner = dict(type='EpochBasedRunner', max_epochs=3)
#3、 Preprocessing of training set and test set ------------
# Several tests have found that pipeline Is an invalid operation , And found that if in the follow-up data Set in pipeline It will lead to an error
# Therefore, it is necessary to modify _base_\datasets\ Data set file under
#4、 Set the path of the dataset ---------------
data_root="D:/AI match / Citrus flower and Fruit Shoot recognition based on visible light image "
data = dict(
samples_per_gpu=1, # batch size
workers_per_gpu=1, # num_workers
train=dict(
type='MultiImageMixDataset',
dataset=dict(
type='CocoDataset',
ann_file='data/voc07_train.json',
img_prefix=data_root,
classes=classes,
filter_empty_gt=False),
),
val=dict(
img_prefix=data_root,
classes=classes,
ann_file='data/voc07_val.json'),
test=dict(
img_prefix=data_root,
classes=classes,
ann_file='data/voc07_test.json'))
#5、 Training strategy settings
optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0001)
optimizer_config = dict(grad_clip=None)
# Learning strategies
lr_config = dict(
_delete_=True,
policy='YOLOX',
warmup='exp',
by_epoch=False,
warmup_by_epoch=True,
warmup_ratio=1,
warmup_iters=5, # 5 epoch
num_last_epochs=50,
min_lr_ratio=0.05)
Training methods : Get into mmdetection The code path of , Save the above configuration file as yolox_s.py, And execute the training code .
Training code : python ./tools/train.py .\yolox_s.py

yolox The pre training model download link of the model is :mmdetection: Update the latest official version simultaneously mmdetectionhttps://github.com/open-mmlab/mmdetection - Gitee.comhttps://gitee.com/monkeycc/mmdetection/tree/master/configs/yolox
边栏推荐
- Oracle/PLSQL: HexToRaw Function
- Memcached Foundation 12
- Flink学习2:应用场景
- Oracle/PLSQL: NumToDSInterval Function
- 学习太极创客 — MQTT 第二章(一)QoS 服务质量等级
- Enterprise digital transformation: informatization and digitalization
- memcached基础13
- Simply learn the entry-level concepts of googlecolab
- C# Tcp服务器如何限制同一个IP的连接数量?
- Getting started with bluecms code auditing
猜你喜欢
为什么传递SPIF_SENDCHANGE标志SystemParametersInfo会挂起?
C语言--职工信息管理系统设计
Flink learning 2: application scenarios
three.js多米诺骨牌js特效
canvas粒子篇之鼠标跟随js特效
TechSmith Camtasia最新2022版详细功能讲解下载
平均风向风速计算(单位矢量法)
Learn from Taiji Maker - mqtt Chapter 2 (I) QoS service quality level
Learn Tai Chi Maker - mqtt Chapter 2 (3) reserved messages
I earned 3W yuan a month from my sideline: the industry you despise really makes money!
随机推荐
Memcached basics 15
What if asreml-r does not converge in operation?
学习太极创客 — MQTT(七)MQTT 主题进阶
宁愿去996也不要待业在家啦!24岁,失业7个月,比上班更惨的,是没班可上
XSS attack (note)
执念斩长河暑期规划
Svg drag dress Kitty Cat
p5.js死亡星球
学习太极创客 — MQTT 第二章(一)QoS 服务质量等级
lottie. JS creative switch button animal head
Look! In June, 2022, the programming language ranking list was released! The first place is awesome
学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息
memcached基础15
Press key to control LED status reversal
Flink学习1:简介
XSS攻击(笔记)
Hot discussion: what are you doing for a meaningless job with a monthly salary of 18000?
"All majors are persuading them to quit." is it actually the most friendly to college students?
bluecms代码审计入门
达梦数据库的卸载