pytorch maskrcnn-benchmark 训练自己数据集报错
错误1:
2019-07-16 10:02:35,438 maskrcnn_benchmark.trainer INFO: Start training
/opt/conda/conda-bld/pytorch_1549633347309/work/aten/src/THCUNN/ClassNLLCriterion.cu:105: void cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *, Dtype *, int, int, int, int, long) [with Dtype = float, Acctype = float]: block: [0,0,0], thread: [31,0,0] Assertion `t >= 0 && t < n_classes` failed.
Traceback (most recent call last):
File "tools/train_net.py", line 174, in <module>
main()
File "tools/train_net.py", line 167, in main
model = train(cfg, args.local_rank, args.distributed)
File "tools/train_net.py", line 73, in train
arguments,
File "/media/data_1/Yang/project/2019/project/maskrcnn-benchmark-yang/maskrcnn-benchmark/maskrcnn_benchmark/engine/trainer.py", line 66, in do_train
loss_dict = model(images, targets)
File "/media/data_1/Yang/software_install/Anaconda0515/envs/maskrcnn_benchmark_yang/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/media/data_1/Yang/project/2019/project/maskrcnn-benchmark-yang/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py", line 52, in forward
x, result, detector_losses = self.roi_heads(features, proposals, targets)
File "/media/data_1/Yang/software_install/Anaconda0515/envs/maskrcnn_benchmark_yang/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/media/data_1/Yang/project/2019/project/maskrcnn-benchmark-yang/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/roi_heads.py", line 26, in forward
x, detections, loss_box = self.box(features, proposals, targets)
File "/media/data_1/Yang/software_install/Anaconda0515/envs/maskrcnn_benchmark_yang/lib/python3.7/site-packages/torch/nn/modules/module.py", line 489, in __call__
result = self.forward(*input, **kwargs)
File "/media/data_1/Yang/project/2019/project/maskrcnn-benchmark-yang/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/box_head/box_head.py", line 56, in forward
[class_logits], [box_regression]
File "/media/data_1/Yang/project/2019/project/maskrcnn-benchmark-yang/maskrcnn-benchmark/maskrcnn_benchmark/modeling/roi_heads/box_head/loss.py", line 151, in __call__
sampled_pos_inds_subset = torch.nonzero(labels > 0).squeeze(1)
RuntimeError: device-side assert triggered
原因是参照写的coco格式类别不需要带背景类,直接从类别1开始,我是这么写的,报上面的错误,把背景类拿掉就可以。
"categories": [
{
"name": "background",
"supercategory": "none",
"id": 0
},
{
"name": "yuanhuan",
"supercategory": "none",
"id": 1
},
{
"name": "yellow",
"supercategory": "none",
"id": 2
},
{
"name": "green",
"supercategory": "none",
"id": 3
},
{
"name": "red",
"supercategory": "none",
"id": 4
},
{
"name": "blue",
"supercategory": "none",
"id": 5
},
{
"name": "indicator",
"supercategory": "none",
"id": 6
}
]
另外,改类别:
maskrcnn_benchmark/config/defaults.py中_C.MODEL.ROI_BOX_HEAD.NUM_CLASSES选项配置错误。
因为默认是使用的COCO数据集,配置的是81。我自己的数据集只有6个分类, 类别应该是6+1
好记性不如烂键盘---点滴、积累、进步!