H1,我正在尝试制作满足简单公式的NN模型。y = X1^2 + X2^2但是当我将 CrossEntropyLoss 用于损失函数时,我收到两个不同的错误消息。首先,当我设置这样的代码时x = torch.randn(batch_size, 2)y_hat = model(x)y = answer(x).long()optimizer.zero_grad()loss = loss_func(y_hat, y)loss.backward()optimizer.step()我收到这条消息RuntimeError: Assertion `cur_target >= 0 && cur_target < n_classes' failed. at c:\programdata\miniconda3\conda-bld\pytorch_1533090623466\work\aten\src\thnn\generic/Cl assNLLCriterion.c:93其次,我像这样更改代码x = torch.randn(batch_size, 2)y_hat = model(x)y = answer(x).long().view(batch_size,1,1)optimizer.zero_grad()loss = loss_func(y_hat, y)loss.backward()optimizer.step()然后我收到消息RuntimeError: multi-target not supported at c:\programdata\miniconda3\conda-bld\pytorch_1533090623466\work\aten\src\thnn\generic/ClassNLLCriterion.c:21我怎么解决这个问题?谢谢。(对不起我的英语)
添加回答
举报
0/150
提交
取消