mmdetection参考博客
https://blog.csdn.net/gaoyi135/article/details/90613895#1dataset_31
csv2coco
https://github.com/spytensor/prepare_detection_dataset/blob/master/csv2coco.py
所有的命令跑之前都看看configs/XXX.py最下面,对应的work_dir建了没有
work_dir = './work_dirs/ga_faster_rcnn_x101_32x4d_fpn_1x'
test部分
1.制作test数据集的假csv,格式为
路径,bbox(4),label_name
2.运用csv2coco把数据集转换为coco的格式
3.把获得的coco格式的test数据集放到对应的位置,然后
修改config文件(以ga_faster_x101_32x4d_fpn_1x.py为例)中的(第5行 img_scale)
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(
type='MultiScaleFlipAug',
img_scale=(683, 512),
flip=False,
transforms=[
dict(type='Resize', keep_ratio=True),
dict(type='RandomFlip'),
dict(type='Normalize', **img_norm_cfg),
dict(type='Pad', size_divisor=32),
dict(type='ImageToTensor', keys=['img']),
dict(type='Collect', keys=['img']),
])
]
修改config文件中的第14行开始的test相关的dict(主要是16,17行)
data = dict(
imgs_per_gpu=2,
workers_per_gpu=2,
train=dict(
type=dataset_type,
ann_file=data_root + 'annotations/instances_train2017.json',
img_prefix=data_root + 'images/' + 'train2017/',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
ann_file=data_root + 'annotations/instances_val2017.json',
img_prefix=data_root + 'images/' + 'val2017/',
pipeline=test_pipeline),
test=dict(
type=dataset_type,
ann_file=data_root + 'annotations/instances_test2017.json',
img_prefix=data_root + 'images/'+ 'test2017/',
pipeline=test_pipeline))
4.运行test.py
2019年9月14号晚上我用的是这个命令
python tools/test.py /xxxx/xxxx/mmdetection/configs/guided_anchoring/ga_faster_x101_32x4d_fpn_1x.py /xxxx/xxxx/mmdetection/work_dirs3/epoch_1.pth --json_out res091420 --eval bbox
此命令将生成包含bbox信息的coco格式的json,如果需要pkl和可视化,mmdet也提供了接口,参考下面的readme应该就懂了
https://github.com/open-mmlab/mmdetection/blob/master/docs/GETTING_STARTED.md
5.对得到的json运行exchange.py
运行时需要修改文件中的第13,14行
data_anno="/xxxx/xxxx/mmdetection/results.pkl.bbox.json"
res_txt = "/xxxx/xxxx/guipang/ZJLAB_ZSD_2019/coco/annotations/res.txt"