0%

mmdetection使用

安装

1.用conda创建一个新的虚拟环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
conda create -n mmdetection python=3.7
conda activate mmdetection

# 安装必要模块
conda install pytorch=1.1.0 torchvision=0.3.0 cudatoolkit=10.0 -c pytorch
pip install cython && pip --no-cache-dir install -r requirements.txt

# 安装mmdetection
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
# 安装
python setup.py install
# 编译
python setup.py develop
  1. demo测试安装是否成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#如果安装成功,则该文件可以运行成功。
#coding=utf-8

from mmdet.apis import init_detector
from mmdet.apis import inference_detector
from mmdet.apis import show_result

# 模型配置文件
config_file = './configs/cascade_rcnn_r50_fpn_1x.py'

# 预训练模型文件
checkpoint_file = '../../checkpoints/cascade_rcnn_r50_fpn_20e_20181123-db483a09.pth'

# 通过模型配置文件与预训练文件构建模型
model = init_detector(config_file, checkpoint_file, device='cuda:0')

# 测试单张图片并进行展示
img = 'demo.jpg'
result = inference_detector(model, img)
show_result(img, result, model.CLASSES)

训练

1
python tools/train.py configs/.py --gpus 1

Config

Soft-NMS

Soft-NMS 改进了之前比较暴力的 NMS,当 IOU 超过某个阈值后,不再直接删除该框,而是降低它的置信度 (得分),如果得分低到一个阈值,就会被排除;但是如果降低后仍然较高,就会被保留。

OHEM

OHEM (online hard example mining),翻译过来就是在线难例挖掘,就是对所有的 ROI 的损失进行评估,选择损失较大的来优化网络,详情移步:OHEM 论文解读

损失选择

针对分类的损失函数可以试试如 GHM-C Loss,针对回归的损失函数可以试试如 GHM-R Loss。IOU可以使用 GIou Loss,Generalized Intersection over Union: A Metric and A Loss for Bounding Box Regression

warmup lr

翻译一下就是对学习率进行预热,最开始是在 ResNet 的论文中提到的一种方法,原始是先在前几个 epoch 或 iter 或目标达到一个水准之前以小于预设值得 lr 进行训练,然后再恢复 lr 到初始值。后来 Facebook 提出了改良版本,详情请移步论文: Gradual warmup[5]

提分点

在训练中对gt进行了0.9-1.1的随机缩放以适应不够精确的标注。

注意点

  1. 若改动框架源代码后,一定要注意重新编译后再使用
    python setup.py develop

  2. 所有数值类型不可以轻易改为int64以下,cuda要求数值符合Long类型

-------------本文结束感谢您的阅读-------------

欢迎关注我的其它发布渠道