yuantn/MI-AOD

Validaiton| TypeError: 'DataContainer' object is not subscriptable

chrissyguo opened this issue · 10 comments

Encounter this error when procssessing validation

[ ] 0/4952, elapsed: 0s, ETA:Traceback (most recent call last):
File "./tools/train.py", line 267, in
main()
File "./tools/train.py", line 242, in main
distributed=distributed, validate=args.no_validate, timestamp=timestamp, meta=meta)
File "/home/bdggj/MI-AOD/mmdet/apis/train.py", line 120, in train_detector
runner.run(data_loaders_L, cfg.workflow, cfg.total_epochs)
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 161, in run
epoch_runner(data_loaders[i], **kwargs)
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/mmcv/runner/epoch_based_runner.py", line 43, in train
self.call_hook('after_train_epoch')
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/mmcv/runner/base_runner.py", line 298, in call_hook
getattr(hook, fn_name)(self)
File "/home/bdggj/MI-AOD/mmdet/core/evaluation/eval_hooks.py", line 71, in after_train_epoch
gpu_collect=self.gpu_collect)
File "/home/bdggj/MI-AOD/mmdet/apis/test.py", line 85, in multi_gpu_test
y_head = model(return_loss=False, rescale=True, **data)
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 705, in forward
output = self.module(*inputs[0], **kwargs[0])
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/bdggj/MI-AOD/mmdet/core/fp16/decorators.py", line 51, in new_func
return old_func(*args, **kwargs)
File "/home/bdggj/MI-AOD/mmdet/models/detectors/base.py", line 164, in forward
return self.forward_test(x, img_metas, return_box=return_box, **kwargs)
File "/home/bdggj/MI-AOD/mmdet/models/detectors/base.py", line 144, in forward_test
return self.simple_test(imgs[0], img_metas[0], return_box=return_box, **kwargs)
File "/home/bdggj/MI-AOD/mmdet/models/detectors/single_stage.py", line 109, in simple_test
y_head_loc_cls = self.bbox_head.get_bboxes(*outs, img_metas, rescale=rescale)
File "/home/bdggj/MI-AOD/mmdet/core/fp16/decorators.py", line 131, in new_func
return old_func(*args, **kwargs)
File "/home/bdggj/MI-AOD/mmdet/models/dense_heads/MIAOD_head.py", line 641, in get_bboxes
img_shape = img_metas[img_id]['img_shape']
TypeError: 'DataContainer' object is not subscriptable
Traceback (most recent call last):
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/torch/distributed/launch.py", line 340, in
main()
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/torch/distributed/launch.py", line 326, in main
sigkill_handler(signal.SIGTERM, None) # not coming back
File "/home/bdggj/anaconda3/envs/miaod/lib/python3.7/site-packages/torch/distributed/launch.py", line 301, in sigkill_handler
raise subprocess.CalledProcessError(returncode=last_return_code, cmd=cmd)
subprocess.CalledProcessError: Command '['/home/bdggj/anaconda3/envs/miaod/bin/python', '-u', './tools/train.py', '--local_rank=0', 'configs/MIAOD.py', '--launcher', 'pytorch']' returned non-zero exit status 1.
Killing subprocess 30225

You can debug it to see what the format of img_metas is. It may be solved by adding [0] after it, like this:
img_shape = img_metas[0][img_id]['img_shape']

Thanks for your reply!

The format of img_metas is 'DataContainer'. FYI

ETA:DataContainer([[{'filename': '/home/bdggj/Documents/data/voc/VOCdevkit/VOC2007/JPEGImages/000001.jpg', 'ori_filename': 'JPEGImages/000001.jpg', 'ori_shape': (500, 353, 3), 'img_shape': (850, 600, 3), 'pad_shape': (864, 608, 3), 'scale_factor': array([1.6997167, 1.7 , 1.6997167, 1.7 ], dtype=float32), 'flip': False, 'flip_direction': None, 'img_norm_cfg': {'mean': array([123.675, 116.28 , 103.53 ], dtype=float32), 'std': array([58.395, 57.12 , 57.375], dtype=float32), 'to_rgb': True}}]])

I also tried img_shape = img_metas[0][img_id]['img_shape'] but does not help.

I think this is a similar problem as #https://github.com/open-mmlab/mmdetection/issues/1501

But I do run this code on a GPU environment.

I have never met this problem when I training with two-stage detectors using mmdetection.

I've met similar problem, and I think you can try these solutions, which may be useful:

  1. img_shape = img_metas.data[img_id]['img_shape']

  2. img_shape = img_metas['img_shape']

  3. try other methods to read DataContainer, such as img_metas[0], img_metas.data, img_metas.data[0], img_metas[img_shape] and so on.

Hope these can help you. (It's a pity that I cannot debug these days.)

Thank you so much!
img_metas.data[0] can work!

你好,我这个之前也报这个错误,然后我也改了,为什么还是有TypeError: 'DataContainer' object is not subscriptable问题

你好,请提供你的输出日志,以及对应的 img_metas 打印结果。


Hello, please provide your output log, and the corresponding img_metas result printed.

我在终端输入python tools/train.py configs/MIAOD.py 运行没有问题,但是输入./script.sh 0时就有问题了

我在终端输入python tools/train.py configs/MIAOD.py 运行没有问题,但是输入./script.sh 0时就有问题了

请提供你的输出日志。


Please provide your output log.

请提供你对应的 img_metas 打印结果。


Please your corresponding img_metas printed result.