mmfewshot icon indicating copy to clipboard operation
mmfewshot copied to clipboard

IndexError: FewShotCocoDataset: list index out of range

Open sanmulab opened this issue 2 years ago • 6 comments

train config: python tools/detection/train.py configs/detection/fsce/coco/fsce_r101_fpn_coco_base-training.py

I want to train my own dataset with mmfewshot, so I modified the categories in BASE_CLASS in coco.py. The result is an error:

Traceback (most recent call last): File "/home/anaconda3/envs/fewshot/lib/python3.7/site-packages/mmcv/utils/registry.py", line 52, in build_from_cfg return obj_cls(**args) File "/home/anaconda3/envs/fewshot/lib/python3.7/site-packages/mmfewshot/detection/datasets/coco.py", line 124, in init **kwargs) File "/home//anaconda3/envs/fewshot/lib/python3.7/site-packages/mmfewshot/detection/datasets/base.py", line 140, in init self.data_infos = self.ann_cfg_parser(ann_cfg) File "/home/anaconda3/envs/fewshot/lib/python3.7/site-packages/mmfewshot/detection/datasets/base.py", line 279, in ann_cfg_parser return self.load_annotations(ann_cfg) File "/home/anaconda3/envs/fewshot/lib/python3.7/site-packages/mmfewshot/detection/datasets/coco.py", line 196, in load_annotations data_infos += self.load_annotations_coco(ann_cfg_['ann_file']) File "/home/anaconda3/envs/fewshot/lib/python3.7/site-packages/mmfewshot/detection/datasets/coco.py", line 215, in load_annotations_coco cat_id = self.coco.get_cat_ids(cat_names=[class_name])[0] IndexError: list index out of range

sanmulab avatar Apr 02 '22 09:04 sanmulab

If the classes are changed, the ALL_CLASSES needs to be modified too.

linyq17 avatar Apr 06 '22 05:04 linyq17

I modified both BASE_CLASSES and ALL_CLASSES in coco.py to my own data class, but still got the same error. My train config as follows: img_norm_cfg = dict( mean=[103.53, 116.28, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True), dict( type='Resize', img_scale=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), (1333, 768), (1333, 800)], keep_ratio=True, multiscale_mode='value'), dict(type='RandomFlip', flip_ratio=0.5), dict( type='Normalize', mean=[103.53, 116.28, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False), dict(type='Pad', size_divisor=32), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']) ] test_pipeline = [ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=(1333, 800), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict( type='Normalize', mean=[103.53, 116.28, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']) ]) ] data_root = 'data/logdet/' data = dict( samples_per_gpu=2, workers_per_gpu=2, train=dict( type='FewShotCocoDataset', save_dataset=False, ann_cfg=[ dict( type='ann_file', ann_file='data/logdet/annotations/instances_train2017.json') ], img_prefix='data/logdet/train2017/', pipeline=[ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True), dict( type='Resize', img_scale=[(1333, 640), (1333, 672), (1333, 704), (1333, 736), (1333, 768), (1333, 800)], keep_ratio=True, multiscale_mode='value'), dict(type='RandomFlip', flip_ratio=0.5), dict( type='Normalize', mean=[103.53, 116.28, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False), dict(type='Pad', size_divisor=32), dict(type='DefaultFormatBundle'), dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']) ], classes='BASE_CLASSES'), val=dict( type='FewShotCocoDataset', ann_cfg=[ dict( type='ann_file', ann_file='data/logdet/annotations/instances_val2017.json') ], img_prefix='data/logdet/train2017/', pipeline=[ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=(1333, 800), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict( type='Normalize', mean=[103.53, 116.28, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']) ]) ], classes='BASE_CLASSES'), test=dict( type='FewShotCocoDataset', ann_cfg=[ dict( type='ann_file', ann_file='data/logdet/annotations/instances_val2017.json') ], img_prefix='data/logdet/train2017/', pipeline=[ dict(type='LoadImageFromFile'), dict( type='MultiScaleFlipAug', img_scale=(1333, 800), flip=False, transforms=[ dict(type='Resize', keep_ratio=True), dict(type='RandomFlip'), dict( type='Normalize', mean=[103.53, 116.28, 123.675], std=[1.0, 1.0, 1.0], to_rgb=False), dict(type='Pad', size_divisor=32), dict(type='ImageToTensor', keys=['img']), dict(type='Collect', keys=['img']) ]) ], test_mode=True, classes='BASE_CLASSES')) evaluation = dict(interval=50000, metric='bbox') optimizer = dict(type='SGD', lr=0.0025, momentum=0.9, weight_decay=0.0001) optimizer_config = dict(grad_clip=None) lr_config = dict( policy='step', warmup='linear', warmup_iters=1000, warmup_ratio=0.001, step=[85000, 100000]) runner = dict(type='IterBasedRunner', max_iters=110000) model = dict( type='FasterRCNN', pretrained='open-mmlab://detectron2/resnet101_caffe', backbone=dict( type='ResNet', depth=101, num_stages=4, out_indices=(0, 1, 2, 3), frozen_stages=1, norm_cfg=dict(type='BN', requires_grad=False), norm_eval=True, style='caffe'), neck=dict( type='FPN', in_channels=[256, 512, 1024, 2048], out_channels=256, num_outs=5, init_cfg=[ dict( type='Caffe2Xavier', override=dict(type='Caffe2Xavier', name='lateral_convs')), dict( type='Caffe2Xavier', override=dict(type='Caffe2Xavier', name='fpn_convs')) ]), 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, 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='L1Loss', loss_weight=1.0)), roi_head=dict( type='StandardRoIHead', 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=50, bbox_coder=dict( type='DeltaXYWHBBoxCoder', target_means=[0.0, 0.0, 0.0, 0.0], target_stds=[0.1, 0.1, 0.2, 0.2]), reg_class_agnostic=False, loss_cls=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0), loss_bbox=dict(type='L1Loss', loss_weight=1.0), init_cfg=[ dict( type='Caffe2Xavier', override=dict(type='Caffe2Xavier', name='shared_fcs')), dict( type='Normal', override=dict(type='Normal', name='fc_cls', std=0.01)), dict( type='Normal', override=dict(type='Normal', name='fc_reg', std=0.001)) ])), 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=-1, pos_weight=-1, debug=False), rpn_proposal=dict( nms_pre=2000, max_per_img=1000, nms=dict(type='nms', iou_threshold=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)), test_cfg=dict( rpn=dict( nms_pre=1000, max_per_img=1000, nms=dict(type='nms', iou_threshold=0.7), min_bbox_size=0), rcnn=dict( score_thr=0.0001, nms=dict(type='soft_nms', iou_threshold=0.5, min_score=0.0001), max_per_img=300))) checkpoint_config = dict(interval=50000) log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')]) custom_hooks = [dict(type='NumClassCheckHook')] dist_params = dict(backend='nccl') log_level = 'INFO' load_from = None resume_from = None workflow = [('train', 1)] use_infinite_sampler = True seed = 42 work_dir = None gpu_ids = [0]

sanmulab avatar Apr 06 '22 05:04 sanmulab

hello,I got the same error. Have you solved it?Thanks

OOICUL avatar Apr 19 '22 08:04 OOICUL

hello, I 'm having the same issue. Did you solve it?

liangzhijia avatar Jan 19 '23 13:01 liangzhijia

The same error for me.

cmjkqyl avatar Jun 30 '23 06:06 cmjkqyl

以fsce方法为例,修改fsce_r101_fpn.py文件里的num_classes(默认为20)为自己数据集的类数量

ManateeSama avatar Dec 02 '23 13:12 ManateeSama