Paddle 高层接口 paddle.model报错

jm2pwxwz  于 2021-12-07  发布在  Java
关注(0)|答案(1)|浏览(430)

在使用高层接口中读取dataset 计算损失函数时报错,提示维度不同,
ValueError: (InvalidArgument) Input(Logits) and Input(Label) should in same shape in dimensions except axis.
[Hint: Expected logits_dims[i] == labels_dims[i], but received logits_dims[i]:2 != labels_dims[i]:1.] (at /paddle/paddle/fluid/operators/softmax_with_cross_entropy_op.cc:145)
[Hint: If you need C++ stacktraces for debugging, please set FLAGS_call_stack_level=2.]
[operator < softmax_with_cross_entropy > error]

构建的dataset 的输出是 iamge, label (shape是 CHW)shape 是要变成 HWC吗,我看示例的dataset是HWC

print(im.shape) # [3, 256, 256]
print(la.shape) #(1, 256, 256)

model.fit(train_dataset,
val_dataset,
epochs=10,
log_freq=1,
batch_size=4,
verbose=1,
)

The loss value printed in the log is the current step, and the metric is the average value of previous step.
Epoch 1/10
---------------------------------------------------------------------------ValueError Traceback (most recent call last) in
4 log_freq=1,
5 batch_size=4,
----> 6 verbose=1,
7
8 )
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/hapi/model.py in fit(self, train_data, eval_data, batch_size, epochs, eval_freq, log_freq, save_dir, save_freq, verbose, drop_last, shuffle, num_workers, callbacks)
1490 for epoch in range(epochs):
1491 cbks.on_epoch_begin(epoch)
-> 1492 logs = self._run_one_epoch(train_loader, cbks, 'train')
1493 cbks.on_epoch_end(epoch, logs)
1494
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/hapi/model.py in _run_one_epoch(self, data_loader, callbacks, mode, logs)
1797 if mode != 'predict':
1798 outs = getattr(self, mode + '_batch')(data[:len(self._inputs)],
-> 1799 data[len(self._inputs):])
1800 if self._metrics and self._loss:
1801 metrics = l[0] for l in outs[0]
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/hapi/model.py in train_batch(self, inputs, labels)
938 print(loss)
939 """
--> 940 loss = self._adapter.train_batch(inputs, labels)
941 if fluid.in_dygraph_mode() and self._input_info is None:
942 self._update_inputs()
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/hapi/model.py in train_batch(self, inputs, labels)
654 * [to_variable(x) for x in inputs])
655
--> 656 losses = self.model._loss(*(to_list(outputs) + labels))
657 losses = to_list(losses)
658 final_loss = fluid.layers.sum(losses)
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py incall(self, *inputs,**kwargs)
882 self._built = True
883
--> 884 outputs = self.forward(*inputs,**kwargs)
885
886 for forward_post_hook in self._forward_post_hooks.values():
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/layer/loss.py in forward(self, input, label)
247 soft_label=self.soft_label,
248 axis=self.axis,
--> 249 name=self.name)
250
251 return ret
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/functional/loss.py in cross_entropy(input, label, weight, ignore_index, reduction, soft_label, axis, name)
1218 soft_label=soft_label,
1219 ignore_index=ignore_index,
-> 1220 axis=axis)
1221 if weight is not None:
1222 weight_gather = core.ops.gather_nd(weight, label) #trans to sample
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/layers/loss.py in softmax_with_cross_entropy(logits, label, soft_label, ignore_index, numeric_stable_mode, return_softmax, axis)
1262 logits, label, 'soft_label', soft_label, 'ignore_index',
1263 ignore_index, 'numeric_stable_mode', numeric_stable_mode, 'axis',
-> 1264 axis)
1265 if not return_softmax:
1266 return loss
ValueError: (InvalidArgument) Input(Logits) and Input(Label) should in same shape in dimensions except axis.
[Hint: Expected logits_dims[i] == labels_dims[i], but received logits_dims[i]:2 != labels_dims[i]:1.] (at /paddle/paddle/fluid/operators/softmax_with_cross_entropy_op.cc:145)
[Hint: If you need C++ stacktraces for debugging, please set FLAGS_call_stack_level=2.]
[operator < softmax_with_cross_entropy > error]

ejk8hzay

ejk8hzay1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

相关问题