mmsegmentation icon indicating copy to clipboard operation
mmsegmentation copied to clipboard

IndexError: The shape of the mask [400, 592] at index 0 does not match the shape of the indexed tensor [220, 325] at index 0

Open GrimreaperZ-creator opened this issue 1 year ago • 5 comments

when I was testing swin transformer using my dateset, I got the above error. During training, the model trained efficiently without any errors. Traceback (most recent call last): File "tools/train.py", line 104, in main() File "tools/train.py", line 100, in main runner.train() File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1706, in train model = self.train_loop.run() # type: ignore File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmengine/runner/loops.py", line 284, in run self.runner.val_loop.run() File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmengine/runner/loops.py", line 363, in run self.run_iter(idx, data_batch) File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmengine/runner/loops.py", line 384, in run_iter self.evaluator.process(data_samples=outputs, data_batch=data_batch) File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmengine/evaluator/evaluator.py", line 60, in process metric.process(data_batch, _data_samples) File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmsegmentation-1.0.0-py3.8.egg/mmseg/evaluation/metrics/iou_metric.py", line 85, in process self.intersect_and_union(pred_label, label, num_classes, File "/home/ubuntu/anaconda3/envs/zyq/lib/python3.8/site-packages/mmsegmentation-1.0.0-py3.8.egg/mmseg/evaluation/metrics/iou_metric.py", line 186, in intersect_and_union pred_label = pred_label[mask] IndexError: The shape of the mask [400, 592] at index 0 does not match the shape of the indexed tensor [220, 325] at index 0

GrimreaperZ-creator avatar Apr 25 '23 14:04 GrimreaperZ-creator

I have encountered the same problem. Have you resolved it?

YangBo0411 avatar Dec 01 '23 02:12 YangBo0411

I have encountered the same problem. Have you resolved it?

zrr1005 avatar Apr 17 '24 07:04 zrr1005

I have solved the problem, it is because the sizes of images and masks are different! OMG

HuiqianLi avatar Jul 03 '24 09:07 HuiqianLi

I have solved the problem, it is because the sizes of images and masks are different! OMG

What was the solution? Is there any config/code change required?

anidh avatar Jul 05 '24 21:07 anidh

I have solved the problem, it is because the sizes of images and masks are different! OMG

What was the solution? Is there any config/code change required?

No, it is just because the pictures of images and masks have different sizes, I have resized them to be the same.

HuiqianLi avatar Jul 06 '24 01:07 HuiqianLi