注:从mmdetection使用coco数据集在faster rcnn训练和测试,到了解crowdhuman数据集标注格式,再到crowdhuman的标注格式转换成coco数据集标注格式,现在就到了最终目的了:训练转换后的Crowd Human数据集。
以下是博主这一过程中整理的记录:
- 【干货】用mmdetection,在COCO数据集上跑通faster R-CNN(测试、训练)
- COCO数据集标注格式详解----object instances
- CrowdHuman数据集格式 ——odgt文件格式
- 【干货】CrowdHuman数据集标注格式odgt转COCO数据集标注格式json(附详细代码)
参考博客:
- mmdetection使用自定义的coco格式数据集进行训练及测试
- mmdetection的configs中的各项参数具体解释
- CrowdHuman: A Benchmark for Detecting Human in a Crowd
训练CrowdHuman数据集是实验室师兄安排给我的任务,因为刚接触目标检测,所以,片面的以为,训练CrowdHuman数据集(已经转换成coco标注格式),就是跟参考博客中的第一篇博客一样,简单设置一下,直接训练。训练的模型真真惨不忍睹。
看一下我的数据集格式:
crowdhuman数据集放在mmdetection文件夹下的data里。
odgt文件是crowdhuman数据集的原标注文件,两个json文件是本次要用的标注文件,是将crowdhuman数据集的odgt文件转换成coco数据标注格式后的json文件。转换过程记录和代码可看上面的第四篇博客。
错误的CrowdHuman训练记录:
这次记录是完全参考第一篇博客的训练过程。当然博主并不是说这篇博客写得有误。错误是针对于CrowdHuman这个数据集而言的。
错误的原因是:博主相当于将crowdhuman的数据集当成了普通数据集处理了,使得训练后验证的量化结果,跟论文所给的实验结论数据相差甚大。
正确的是应该参考论文中的实验细节,根据它的要求,来进行调整参数。
这是我的test的结果,可以看得出来,AP值很低(AP 应该是IoU=0.5那行)。
这是论文中给的实验数据。
这是训练的模型进行测试一张图片的结果,效果也是极差。(测试代码 这篇博客里有)
对比一下coco数据集训练的模型,跑上面图片的结果:
上面训练的模型,博主只改动了以下几处:
首先说明的是我的数据集类别一共只有2个,分别是:‘person’, ‘mask’, 。且我跑的模型是’configs/faster_rcnn_r50_fpn_1x.py’。
1.定义数据种类,需要修改的地方在mmdetection/mmdet/datasets/coco.py。把CLASSES的那个tuple改为自己数据集对应的种类tuple即可。例如:
CLASSES = ('person', 'mask')
2、接着在mmdetection/mmdet/core/evaluation/class_names.py修改coco_classes数据集类别,这个关系到后面test的时候结果图中显示的类别名称。例如:
def coco_classes():
return [
'person', 'mask'
]
3、修改configs/faster_rcnn_r50_fpn_1x.py中的model字典中的num_classes、data字典中的img_scale和optimizer中的lr(学习率)。例如:
num_classes=2,#类别数+1,虽然是两个类别,但其实只跑了person这一类而已
img_scale=(640,478), #输入图像尺寸的最大边与最小边(train、val三处都要修改)
optimizer = dict(type='SGD', lr=0.0025, momentum=0.9, weight_decay=0.0001) #当gpu数量为8时,lr=0.02;当gpu数量为4时,lr=0.01;我只要一个gpu,所以设置lr=0.0025
ok,以上就是修改的过程,据博主卑微的经验,这样的修改,应该是初级的,也就是说,适用于所有自定义的coco格式的数据集训练,具体的改进调优,则是在这基础之上再进行修改。
正确的CrowdHuman训练记录:
在Crowdhuman的论文中,实验的细节原文是这样说的:
We use the same setting of anchor scales as [15] and [16]. For all the experiments related to full body detection, we modify the height v.s. width ratios of anchors as {1 : 1,1.5 : 1,2 : 1,2.5 : 1,3 : 1} in consideration of the human body shape. While for visible body detection and human head detection, the ratios are set to {1 : 2,1 : 1,2 : 1}, in comparison with the original papers. The input image sizes of Caltech and CityPersons are set to 2× and 1× of the original images according to [31]. As the images of CrowdHuman and MSCOCO are both collected from the Internet with various sizes, we resize the input so that their short edge is at 800 pixels while the long edge should be no more than 1400 pixels at the same time. The input sizes of Brainwash is set as 640 × 480.
We train all datasets with 600k and 750k iterations for FPN and RetinaNet, respectively. The base learning rate is set to 0.02 and decreased by a factor of 10 after 150k and 450k for FPN, and 180k and 560k for RetinaNet. The Stochastic Gradient Descent (SGD) solver is adopted to optimize the networks on 8 GPUs. A mini-batch involves 2 images per GPU, except for CityPersons where a mini-batch involves only 1 image due to the physical limitation of GPU memory. Weight decay and momentum are set to 0.0001 and 0.9. We do not finetune the batch normalization [11] layers. Multi-scale training/testing are not applied to ensure fair comparisons.
中文翻译:
我们使用[15]和[16]中相同的锚尺度设置。对于所有与整体人体检测相关的试验,我们修正锚窗的高宽比为{1:1, 1.5:1, 2:1, 2.5:1, 3:1},以适应人体形状。而对于可见人体检测和头部检测,比例设置为{1:2, 1:1, 2:1}。根据[31],Caltech和CityPersons的输入图像尺寸设置为原图像的2倍和1倍。因为CrowdHuman和MSCOCO的图像都是从互联网上收集的,尺寸不一,我们改变图像尺寸,使其短边为800像素,同时长边不应超过1400像素。Brainwash的输入大小设置为640×480。
对于FPN和RetinaNet,我们训练所有的数据集迭代次数分别为60万次和75万次。基准学习速率为0.02,对于FPN,在15万次和45万次后除以10,对于RetinaNet在18万次和56万次后除以10。采用SGD在8GPU上优化网络。Mini-batch大小为每GPU 2幅图像,在CityPersons上是个例外,由于GPU内存的限制所以为每GPU 1幅图像。权值衰减和动量设置为0.0001和0.9。我们没有精调批归一化层[11]。公平起见,没有进行多尺度训练/测试。
针对论文所说的,我的configs/faster_rcnn_r50_fpn_1x.py
文件内容如下(后文有具体的修改过解析):
# model settings
model = dict(
type='FasterRCNN', #model类型
pretrained='modelzoo://resnet50', #预训练模型
backbone=dict(
type='ResNet', #backbone类型
depth=50, #网络层数
num_stages=4, #resnet的stage数量
out_indices=(0, 1, 2, 3), #输出的stage序号
frozen_stages