open-mmlab / mmdetection

OpenMMLab Detection Toolbox and Benchmark
https://mmdetection.readthedocs.io
Apache License 2.0
29.61k stars 9.47k forks source link

The num_classes (without bg) changed but IndexError: list index out of range #3408

Closed sunnyisabaster closed 4 years ago

sunnyisabaster commented 4 years ago

Checklist

  1. I have searched related issues but cannot get the expected help.
  2. The bug has not been fixed in the latest version.

Describe the bug IndexError: list index out of range

Reproduction

  1. What command or script did you run? python tools/train.py ./configs/cascade_rcnn/cascade_rcnn_x101_64x4d_fpn_20e_coco.py A placeholder for the command.
  2. Did you make any modifications on the code or config? Did you understand what you have modified?

    model settings

    model = dict( type='CascadeRCNN', pretrained='torchvision://resnet50', backbone=dict( type='ResNet', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=1, norm_cfg=dict(type='BN', requires_grad=True), norm_eval=True, style='pytorch'), neck=dict( type='FPN', in_channels=[256, 512, 1024, 2048], out_channels=256, num_outs=5), rpn_head=dict( type='RPNHead', in_channels=256, feat_channels=256, anchor_generator=dict( type='AnchorGenerator', scales=[8], ratios=[0.5, 1.0, 2.0], strides=[4, 8, 16, 32, 64]), bbox_coder=dict( type='DeltaXYWHBBoxCoder', target_means=[.0, .0, .0, .0], target_stds=[1.0, 1.0, 1.0, 1.0]), loss_cls=dict( type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0), loss_bbox=dict(type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)), roi_head=dict( type='CascadeRoIHead', num_stages=3, stage_loss_weights=[1, 0.5, 0.25], bbox_roi_extractor=dict( type='SingleRoIExtractor', roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0), out_channels=256, featmap_strides=[4, 8, 16, 32]), bbox_head=[ dict( type='Shared2FCBBoxHead', in_channels=256, fc_out_channels=1024, roi_feat_size=7, num_classes=1, bbox_coder=dict( type='DeltaXYWHBBoxCoder', target_means=[0., 0., 0., 0.], target_stds=[0.1, 0.1, 0.2, 0.2]), reg_class_agnostic=True, loss_cls=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0)), dict( type='Shared2FCBBoxHead', in_channels=256, fc_out_channels=1024, roi_feat_size=7, num_classes=1, bbox_coder=dict( type='DeltaXYWHBBoxCoder', target_means=[0., 0., 0., 0.], target_stds=[0.05, 0.05, 0.1, 0.1]), reg_class_agnostic=True, loss_cls=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0)), dict( type='Shared2FCBBoxHead', in_channels=256, fc_out_channels=1024, roi_feat_size=7, num_classes=1, bbox_coder=dict( type='DeltaXYWHBBoxCoder', target_means=[0., 0., 0., 0.], target_stds=[0.033, 0.033, 0.067, 0.067]), reg_class_agnostic=True, loss_cls=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), loss_bbox=dict(type='SmoothL1Loss', beta=1.0, loss_weight=1.0)) ]))

    model training and testing settings

    train_cfg = dict( rpn=dict( assigner=dict( type='MaxIoUAssigner', pos_iou_thr=0.7, neg_iou_thr=0.3, min_pos_iou=0.3, match_low_quality=True, ignore_iof_thr=-1), sampler=dict( type='RandomSampler', num=256, pos_fraction=0.5, neg_pos_ub=-1, add_gt_as_proposals=False), allowed_border=0, pos_weight=-1, debug=False), rpn_proposal=dict( nms_across_levels=False, nms_pre=2000, nms_post=2000, max_num=2000, nms_thr=0.7, min_bbox_size=0), rcnn=[ dict( assigner=dict( type='MaxIoUAssigner', pos_iou_thr=0.5, neg_iou_thr=0.5, min_pos_iou=0.5, match_low_quality=False, ignore_iof_thr=-1), sampler=dict( type='RandomSampler', num=512, pos_fraction=0.25, neg_pos_ub=-1, add_gt_as_proposals=True), pos_weight=-1, debug=False), dict( assigner=dict( type='MaxIoUAssigner', pos_iou_thr=0.6, neg_iou_thr=0.6, min_pos_iou=0.6, match_low_quality=False, ignore_iof_thr=-1), sampler=dict( type='RandomSampler', num=512, pos_fraction=0.25, neg_pos_ub=-1, add_gt_as_proposals=True), pos_weight=-1, debug=False), dict( assigner=dict( type='MaxIoUAssigner', pos_iou_thr=0.7, neg_iou_thr=0.7, min_pos_iou=0.7, match_low_quality=False, ignore_iof_thr=-1), sampler=dict( type='RandomSampler', num=512, pos_fraction=0.25, neg_pos_ub=-1, add_gt_as_proposals=True), pos_weight=-1, debug=False) ]) test_cfg = dict( rpn=dict( nms_across_levels=False, nms_pre=1000, nms_post=1000, max_num=1000, nms_thr=0.7, min_bbox_size=0), rcnn=dict( score_thr=0.05, nms=dict(type='nms', iou_threshold=0.5), max_per_img=100))

3. What dataset did you use?
{"info": "spytensor created", "license": ["license"], "annotations": [{"segmentation": [[292.5, 0.5, 315.5, 14.5, 370.5, 29.5, 384.5, 33.5, 409.5, 19.5, 420.5, 7.5, 445.5, 0.5]], "area": 1.0, "iscrowd": 0, "image_id": 0, "bbox": [292.0, 0.0, 445.0, 33.0], "category_id": 0, "id": 14}], "images": [{"file_name": "aja-helo-1H000314_2019-10-14_1002/0.jpg", "height": 720, "width": 1280, "id": 0}], "categories": [{"id": 0, "name": "fish"}]}

Environment sys.platform: linux Python: 3.7.7 (default, Mar 23 2020, 22:36:06) [GCC 7.3.0] CUDA available: True CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 10.1, V10.1.243 GPU 0,1: GeForce GTX 1080 Ti GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.5.0 PyTorch compiling details: PyTorch built with:

TorchVision: 0.6.0a0+82fd1c8 OpenCV: 4.3.0 MMCV: 1.0.2 MMDetection: 2.3.0rc0+d613f21 MMDetection Compiler: GCC 7.3 MMDetection CUDA Compiler: 10.1


**Error traceback**
2020-07-26 10:50:59,013 - mmdet - INFO - load model from: open-mmlab://resnext101_64x4d
loading annotations into memory...
Done (t=0.13s)
creating index...
index created!
loading annotations into memory...
Done (t=0.03s)
creating index...
index created!
2020-07-26 10:51:01,310 - mmdet - INFO - Start running, host: sun@6339579bb0bf, work_dir: /data/mmdetection/work_dirs/cascade_rcnn_x101_64x4d_fpn_20e_coco
2020-07-26 10:51:01,310 - mmdet - INFO - workflow: [('train', 1)], max: 20 epochs
2020-07-26 10:51:49,071 - mmdet - INFO - Saving checkpoint at 1 epochs
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 3409/3409, 4.9 task/s, elapsed: 697s, ETA:     0sTraceback (most recent call last):
  File "tools/train.py", line 153, in <module>
    main()
  File "tools/train.py", line 149, in main
    meta=meta)
  File "/mmdetection/mmdet/apis/train.py", line 128, in train_detector
    runner.run(data_loaders, cfg.workflow, cfg.total_epochs)
  File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 122, in run
    epoch_runner(data_loaders[i], **kwargs)
  File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 46, in train
    self.call_hook('after_train_epoch')
  File "/opt/conda/lib/python3.7/site-packages/mmcv/runner/base_runner.py", line 282, in call_hook
    getattr(hook, fn_name)(self)
  File "/mmdetection/mmdet/core/evaluation/eval_hooks.py", line 28, in after_train_epoch
    self.evaluate(runner, results)
  File "/mmdetection/mmdet/core/evaluation/eval_hooks.py", line 32, in evaluate
    results, logger=runner.logger, **self.eval_kwargs)
  File "/mmdetection/mmdet/datasets/coco.py", line 401, in evaluate
    result_files, tmp_dir = self.format_results(results, jsonfile_prefix)
  File "/mmdetection/mmdet/datasets/coco.py", line 361, in format_results
    result_files = self.results2json(results, jsonfile_prefix)
  File "/mmdetection/mmdet/datasets/coco.py", line 293, in results2json
    json_results = self._det2json(results)
  File "/mmdetection/mmdet/datasets/coco.py", line 230, in _det2json
    data['category_id'] = self.cat_ids[label]
IndexError: list index out of range
sunnyisabaster commented 4 years ago

I also marked /mmdetection/mmdet/datasets/custom.py

if self.custom_classes:

self.data_infos = self.get_subset_by_classes()

but it cannot help me to fix this problem.

likyoo commented 4 years ago

I have the same question

sunnyisabaster commented 4 years ago

I have the same question

Hey man, have you solved that? It's annoying...

shinya7y commented 4 years ago

Pasting full config shown by train.py or print_config.py would be helpful. If subset classes are specified (e.g., classes = ('person', 'bicycle', 'car')), fix like this may be needed.

sunnyisabaster commented 4 years ago

The problem fixed. I tried to print model.CLASSES in tools/train.py, then I found classes were not wanted (it was 80 classes). Actually I have commented class lines by '#' and gave my custom class, but it doesn't work. So, I made a custom file and register that, now it's working.

sunnyisabaster commented 4 years ago

Pasting full config shown by train.py or print_config.py would be helpful. If subset classes are specified (e.g., classes = ('person', 'bicycle', 'car')), fix like this may be needed.

Thanks mate!

sunnyisabaster commented 4 years ago

To be honest, I need to compile the command when I lost connection with the remote server:

python setup.py build_ext --inplace export PYTHONPATH=${PWD}:$PYTHONPATH pip install -r requirements.txt

The last line can only run once.

casiahnu commented 4 years ago

Pasting full config shown by train.py or print_config.py would be helpful. If subset classes are specified (e.g., classes = ('person', 'bicycle', 'car')), fix like this may be needed.

Pasting full config shown by train.py or print_config.py would be helpful. If subset classes are specified (e.g., classes = ('person', 'bicycle', 'car')), fix like this may be needed.

Thanks mate!

Have you solved it? I didn't solve it. My wechat is 18810220665