类别数有20个
input大小 [8, 20, 512, 512]
label大小 [8, 1, 512, 512]
weight 是 [20]
结果就会报错:
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 884, in __call__
outputs = self.forward(*inputs, **kwargs)
File "work/FocalLoss.py", line 27, in forward
logpt = - F.cross_entropy(input, target, weight=weight, axis =1,ignore_index = self.ignore_index)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/functional/loss.py", line 1222, in cross_entropy
weight_gather = core.ops.gather_nd(weight, label) #trans to sample
ValueError: (InvalidArgument) Input(Index).shape[-1] should be no greater than Input(X).rank
[Hint: Expected index_dims[index_dims_size - 1] <= x_dims_size, but received index_dims[index_dims_size - 1]:512 > x_dims_size:1.] (at /paddle/paddle/fluid/operators/gather_nd_op.cc:47)
[Hint: If you need C++ stacktraces for debugging, please set `FLAGS_call_stack_level=2`.]
[operator < gather_nd > error]
这意思,难道weight要 [20, 512]嘛??