- 标题:多维输入CrossEntropyLoss报错
- 版本、环境信息:
Paddle version: 2.1.2
Paddle With CUDA: True
OS: Deepin 20.2
Python version: 3.7.3
CUDA version: 9.2.148
cuDNN version: None.None.None
Nvidia driver version: 460.39
- 复现信息:
- 按照文档:https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/CrossEntropyLoss_cn.html
- 做一个[5,2,100]的input;再做一个[5,100]的label;即N=5,C=2,d1=100,调用默认loss=paddle.nn.CrossEntropyLoss()
- loss(input, label)报错: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]:100.] (at /paddle/paddle/fluid/operators/softmax_with_cross_entropy_op.cc:150)
[operator < softmax_with_cross_entropy > error]
- 问题描述:应该是要求logits和label所有对应周必须相等,也就是input的C要等于label的d1;但用paddle.nn.LogSoftmax(axis=1)+paddle.nn.loss.NLLLoss()没这个错误
2条答案
按热度按时间6gpjuf901#
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~
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 API,FAQ,Github Issue and AI community to get the answer.Have a nice day!
fsi0uk1n2#
你好目前CrossEntropyLoss的文档说明确实存在问题,最近已经在develop分支中对其进行了修复
input的形状中通道需要放在最后,将input的形状变为[5,100,2]应该能正常运行了