MMDetection 快速开始,训练自定义数据集
本文将快速引导使用 MMDetection ,记录了实践中需注意的一些问题。
环境准备
基础环境
- Nvidia 显卡的主机
- Ubuntu 18.04
- 系统安装,可见 制作 USB 启动盘,及系统安装
- Nvidia Driver
- 驱动安装,可见 Ubuntu 初始配置 - Nvidia 驱动
开发环境
下载并安装 Anaconda ,之后于 Terminal 执行:
# 创建 Python 虚拟环境
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab# 安装 PyTorch with CUDA
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2 -c pytorch -y# 安装 MMCV
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.6.0/index.html# 安装 MMDetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt
pip install -v -e .
pytorch==1.7.0
时多卡训练会发生问题,需参考此 Issue。命令参考:
conda install pytorch==1.7.0 torchvision==0.8.1 cudatoolkit=10.2 -c pytorch -ypip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.7.0/index.html
更多安装方式,可见官方文档:
- MMDetection - Installation
- MMCV - Installation
现有模型进行推断
Faster RCNN
以 R-50-FPN 为例,下载其 model 文件到 mmdetection/checkpoints/
。之后,进行推断,
conda activate open-mmlabcd mmdetection/python demo/image_demo.py \
demo/demo.jpg \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
现有模型进行测试
准备数据集
下载 COCO 数据集,如下放进 mmdetection/data/coco/
目录,
mmdetection
├── data
│ ├── coco
│ │ ├── annotations
│ │ ├── train2017
│ │ ├── val2017
│ │ ├── test2017
测试现有模型
cd mmdetection/# single-gpu testing
python tools/test.py \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
--out results.pkl \
--eval bbox \
--show# multi-gpu testing
bash tools/dist_test.sh \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
2 \
--out results.pkl \
--eval bbox
效果如下,
结果如下,
loading annotations into memory...
Done (t=0.33s)
creating index...
index created!
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 5000/5000, 15.3 task/s, elapsed: 328s, ETA: 0s
writing results to results.pklEvaluating bbox...
Loading and preparing results...
DONE (t=0.89s)
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=26.17s).
Accumulating evaluation results...
DONE (t=4.10s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.374
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=1000 ] = 0.581
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=1000 ] = 0.404
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.212
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = 0.410
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.481
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.517
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=300 ] = 0.517
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=1000 ] = 0.517
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=1000 ] = 0.326
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=1000 ] = 0.557
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=1000 ] = 0.648
OrderedDict([('bbox_mAP', 0.374), ('bbox_mAP_50', 0.581), ('bbox_mAP_75', 0.404), ('bbox_mAP_s', 0.212), ('bbox_mAP_m', 0.41), ('bbox_mAP_l', 0.481), ('bbox_mAP_copypaste', '0.374 0.581 0.404 0.212 0.410 0.481')])
标准数据集训练模型
准备数据集
同前一节的 COCO 数据集。
准备配置文件
配置文件为 configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py
。
需要依照自己的 GPU 情况,修改 lr
学习速率参数,说明如下:
lr=0.005
for 2 GPUs * 2 imgs/gpulr=0.01
for 4 GPUs * 2 imgs/gpulr=0.02
for 8 GPUs and 2 img/gpu (batch size = 8*2 = 16), DEFAULTlr=0.08
for 16 GPUs * 4 imgs/gpu
_base_ = ['../_base_/models/faster_rcnn_r50_fpn.py','../_base_/datasets/coco_detection.py','../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]
# optimizer
optimizer = dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001)
训练模型
cd mmdetection/# single-gpu training
python tools/train.py \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
--work-dir _train# multi-gpu training
bash ./tools/dist_train.sh \
configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
2 \
--work-dir _train
自定义数据集训练模型
自定义数据集
这里从 Pascal VOC 数据集拿出 cat
作为自定义数据集来演示,
conda activate open-mmlab# Dataset Management Framework (Datumaro)
pip install 'git+https://github.com/openvinotoolkit/datumaro'
# pip install tensorflowdatum convert --input-format voc --input-path ~/datasets/VOC2012 \
--output-format coco --output-dir ~/datasets/coco_voc2012_cat \
--filter '/item[annotation/label="cat"]'
数据集需要是 COCO 格式,以上直接用 datum
从 VOC 拿出 cat
并转为了 COCO 格式。
准备配置文件
添加 configs/voc_cat/faster_rcnn_r50_fpn_1x_voc_cat.py
配置文件,内容如下:
# The new config inherits a base config to highlight the necessary modification
_base_ = ['../_base_/models/faster_rcnn_r50_fpn.py','../_base_/datasets/coco_detection.py','../_base_/schedules/schedule_1x.py', '../_base_/default_runtime.py'
]# We also need to change the num_classes in head to match the dataset's annotation
model = dict(roi_head=dict(bbox_head=dict(num_classes=1)))# Modify dataset related settings
dataset_type = 'COCODataset'
classes = ('cat',)
data_root = '/home/john/datasets/'
data = dict(train=dict(img_prefix=data_root + 'VOC2012/JPEGImages/',classes=classes,ann_file=data_root + 'coco_voc2012_cat/annotations/instances_train.json'),val=dict(img_prefix=data_root + 'VOC2012/JPEGImages/',classes=classes,ann_file=data_root + 'coco_voc2012_cat/annotations/instances_val.json'),test=dict(img_prefix=data_root + 'VOC2012/JPEGImages/',classes=classes,ann_file=data_root + 'coco_voc2012_cat/annotations/instances_val.json'))
evaluation = dict(interval=100)# Modify schedule related settings
optimizer = dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001)
total_epochs = 10000# Modify runtime related settings
checkpoint_config = dict(interval=10)# We can use the pre-trained model to obtain higher performance
# load_from = 'checkpoints/*.pth'
model
配置num_classes=1
为类别数量dataset
配置为准备的自定义数据集schedule
配置训练的lr
及迭代轮次total_epochs
runtime
可配置checkpoint
间隔多少存一个。默认 1 epoch 1 个,空间不够用MMDetection 快速开始,训练自定义数据集相关推荐
- 目标检测第6步:YOLOv5(5.0)如何在Colab中训练自定义数据集?(更新时间:2022.3.22)
(请先看这篇文章:本博打开方式!!!请详读!!!请详读!!!请详读!!!_Cat-CSDN博客) 如果看完这篇博文,你的问题还是没有解决,那么请关注我的公众号,后台发消息给我吧,当天回复! 目录 一. ...
- mmdetection实战,训练扑克牌数据集(VOC格式)并测试计算mAP
mmdetection实战,训练扑克牌数据集(VOC格式)并测试计算mAP 一.数据集准备 二.mmdetection的安装 三.修改相关文件 1. 修改class_names.py文件 2. 修改v ...
- Scaled-YOLOv4 快速开始,训练自定义数据集
代码: https://github.com/ikuokuo/start-scaled-yolov4 Scaled-YOLOv4 代码: https://github.com/WongKinYiu/S ...
- 基于MMRotate训练自定义数据集 做旋转目标检测 2022-3-30
本文目录 简述 1.MMrotate下载 2.环境安装 3.自定义数据集制作 3.1 roLabelImg 打标签 3.2 生成DOTA数据集格式的标签 3.3 数据集裁剪(split) 4.修改配置 ...
- CenterNet2实战:手把手带你实现使用CenterNet2训练自定义数据集
1.CenterNet2 介绍 论文地址:https://arxiv.org/abs/2103.07461 GitHub地址:https://github.com/xingyizhou/CenterN ...
- 模糊度判断:史上最详细图像质量评价(IQA)-训练自定义数据集--第三节
这章节我会讲解的是我在工作上自己开发的项目,模糊度判断,该项目我是将图像质量评价论文–hypernet网络移植到mmclassification中进行图片质量评估,若有地方说错的我会第一时间纠正,如果 ...
- YOLOv4训练自定义数据集
目录 一. darknet 1.环境配置 2.权重下载 3.数据集处理 4.修改配置文件 4.1 修改data/voc.names 4.2 修改data/voc.data 4.3 修改cfg/yolo ...
- DeepLabV3+训练自定义数据集实例(1)
1.下载数据集 在这里面,用的是狗猫数据集中的猫数据的一部分,官方下载地址为:https://www.kaggle.com/c/dogs-vs-cats/data 2.使用labelme最新版打标签 ...
- YOLOv8训练自定义数据集(超详细)
借鉴 https://blog.csdn.net/qq_40716944/article/details/128648001 一.准备训练环境 安装 requirements.txt 下载:https ...
最新文章
- ICML 2021:矩阵乘法无需相乘,速度提升100倍,MIT开源最新近似算法
- 如何自定义制表符到空格的转换因子?
- 一个词法分析器源码的剖析
- 《说服力——让你的PPT会说话》读书笔记02
- CF603E-Pastoral Oddities【CDQ分治,可撤销并查集】
- 2017年计算机三级网络技术试题,2017年计算机三级网络技术考前试题及答案(8)
- 【金三银四】启动mysql服务器
- MVC 页面传参到另一个页面
- 如何生成可变表头的excel
- Linux下 对文件行数打乱(乱序排列)
- 怎么改wps表格中折线图的横坐标?
- VS 2005 2008 项目模板丢失问题
- VMware时钟不准的解决之道
- wps打印错误未定义书签怎么解决_wps目录中错误未定义书签怎么解决?
- 深入探究 null 和 undefined 区别
- Cookie中path总结
- 数据结构和算法经典书籍
- android项目飞机大战,飞机大战android版源代码
- Visual Studio 2008 工作环境 切换
- python 公主连接_ss
热门文章
- 目标检测第6步:YOLOv5(5.0)如何在Colab中训练自定义数据集?(更新时间:2022.3.22)