mmdetection: TypeError: 'NoneType' object is not subscriptable
Describe the bug While training the model I am facing this error, not sure where am I going wrong.
Reproduction
- What command or script did you run?
!python tools/train.py 'configs/truck/cascade_mask_rcnn_swin_small_patch4_window7_mstrain_480-800_giou_4conv1f_adamw_3x_truck.py'
Using the pre-trained model as a checkpoint for transfer learning.
-
Did you make any modifications on the code or config? Did you understand what you have modified? Yes, I modified the code for custom object detection for the custom dataset. Using a custom dataset with modifications made in the config/swin/xxx file and changed the path in the _ base _ variable in the config file downloaded from the repository.
-
What dataset did you use? custom dataset with a json file annotations
Environment
-
Please run
python mmdet/utils/collect_env.pyto collect necessary environment information and paste it here. I don’t think it is env problem, I have no issues running a pre-trained model by itself. -
You may add addition that may be helpful for locating the problem, such as
- How you installed PyTorch [e.g., pip, conda, source]
- Other environment variables that may be related (such as
$PATH,$LD_LIBRARY_PATH,$PYTHONPATH, etc.)
I have modified the files that were mentioned in the config files like num_classes and adding data variables with paths, enabling optimizer_config and in models/cascade_xxx.py.
Error traceback
File "tools/train.py", line 188, in <module>
main()
File "tools/train.py", line 177, in main
train_detector(
File "/home/w/cbn/CBNetV2/mmdet/apis/train.py", line 185, in train_detector
runner.run(data_loaders, cfg.workflow)
File "/home/w/cbn/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 127, in run
epoch_runner(data_loaders[i], **kwargs)
File "/home/w/cbn/lib/python3.8/site-packages/mmcv/runner/epoch_based_runner.py", line 47, in train
for i, data_batch in enumerate(self.data_loader):
File "/home/w/cbn/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in __next__
data = self._next_data()
File "/home/w/cbn/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
return self._process_data(data)
File "/home/w/cbn/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
data.reraise()
File "/home/w/cbn/lib/python3.8/site-packages/torch/_utils.py", line 425, in reraise
raise self.exc_type(msg)
TypeError: Caught TypeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/w/cbn/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/home/w/cbn/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/w/cbn/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/w/cbn/CBNetV2/mmdet/datasets/custom.py", line 194, in __getitem__
data = self.prepare_train_img(idx)
File "/home/w/cbn/CBNetV2/mmdet/datasets/custom.py", line 217, in prepare_train_img
return self.pipeline(results)
File "/home/w/cbn/CBNetV2/mmdet/datasets/pipelines/compose.py", line 40, in __call__
data = t(data)
File "/home/w/cbn/CBNetV2/mmdet/datasets/pipelines/loading.py", line 371, in __call__
results = self._load_masks(results)
File "/home/w/cbn/CBNetV2/mmdet/datasets/pipelines/loading.py", line 323, in _load_masks
[self._poly2mask(mask, h, w) for mask in gt_masks], h, w)
File "/home/w/cbn/CBNetV2/mmdet/datasets/pipelines/loading.py", line 323, in <listcomp>
[self._poly2mask(mask, h, w) for mask in gt_masks], h, w)
File "/home/w/cbn/CBNetV2/mmdet/datasets/pipelines/loading.py", line 281, in _poly2mask
elif isinstance(mask_ann['counts'], list):
TypeError: 'NoneType' object is not subscriptable
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (1 by maintainers)
I have no idea lol - it just seems to does automatically (I guess)
I agree - sounds like an error in the number and/or naming of classes. This happened to me quite often when I began to use MMDetection. If you share your config file, we could help more. BTW, I’m curious - are you using a model where the backbone network is Swin-S and the head is Cascade Mask R-CNN? I cannot find anything like that here - the closest one (but it’s Mask R-CNN, not Cascade) is this
https://github.com/open-mmlab/mmdetection/blob/master/configs/swin/mask_rcnn_swin-s-p4-w7_fpn_fp16_ms-crop-3x_coco.py
that seems to be a problem with your dataset - double-check the type. How many classes are you classifying? are you sure the format is correct?