PaddlePaddle / PaddleSeg

Easy-to-use image segmentation library with awesome pre-trained model zoo, supporting wide-range of practical tasks in Semantic Segmentation, Interactive Segmentation, Panoptic Segmentation, Image Matting, 3D Segmentation, etc.
https://arxiv.org/abs/2101.06175
Apache License 2.0
8.68k stars 1.68k forks source link

自定义数据集训练报错`The input tensor's dimension should be equal to the axis's size. But received input tensor's dimension is 5, axis's size is 4` #1427

Closed hhxdestiny closed 3 years ago

hhxdestiny commented 3 years ago

BML_CodeLab使用UNet3Plus模型训练自定义数据集,in_channels=3,num_classes=2,batch_size=4, 报错如下,

Traceback (most recent call last):
  File "test.py", line 65, in <module>
    use_vdl=True
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleseg/core/train.py", line 185, in train
    edges=edges)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleseg/core/train.py", line 46, in loss_computation
    loss_list.append(losses['coef'][i] * loss_i(logits, labels))
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 902, in __call__
    outputs = self.forward(*inputs, **kwargs)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddleseg/models/losses/binary_cross_entropy_loss.py", line 141, in forward
    label = label.transpose((0, 3, 1, 2))
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/nn.py", line 5494, in transpose
    out, _ = core.ops.transpose2(x, 'axis', perm)
ValueError: (InvalidArgument) The input tensor's dimension should be equal to the axis's size. But received input tensor's dimension is 5, axis's size is 4
  [Hint: Expected x_rank == axis_size, but received x_rank:5 != axis_size:4.] (at /paddle/paddle/fluid/operators/transpose_op.cc:47)
  [operator < transpose2 > error]

打印了报错行out, _ = core.ops.transpose2(x, 'axis', perm)的参数

x.shape: [1, 512, 512, 3, 2]
perm: (0, 3, 1, 2)

请问可能是哪一块的问题?

juncaipeng commented 3 years ago

paddle中,transpose的输入x和axis必须rank相同。如上,x的rank是5,axis的rank是4,所以报错。

hhxdestiny commented 3 years ago

@juncaipeng 请问输入图片resize后shape: [512, 512, 3],然后batch_size是1,所以shape应该是[1, 512, 512, 3],为何打印结果显示x.shape: [1, 512, 512, 3, 2]?第四维的2表示的是label吗?