【问题标题】:I have an error on Pytorch and in particular with nllloss我在 Pytorch 上遇到错误,尤其是在 nllloss 上
【发布时间】:2021-02-11 08:36:12
【问题描述】:

我想应用标准,其中 criterion = nn.NLLLoss() 我将它应用于输出和标签

loss = criterion(output.view(-1,1), labels.long())

地点:

*标签的形状

labels
tensor([ 1,  4,  1,  1,  4,  1,  2,  3,  2,  4,  2,  3,  3,  4,
         0,  4])
output
tensor([ 0.1829,  0.1959,  0.1909,  0.1895,  0.1914,  0.1883,  0.1895,
         0.1884,  0.1865,  0.1931,  0.1883,  0.1917,  0.1942,  0.1937,
         0.1897,  0.1934])

输出的形状 torch.Size([16])

在下面一行:

loss = criterion(output.view(-1,1), labels.long())

我收到此错误:

错误是:

RuntimeError: 断言 `cur_target >= 0 && cur_target

有什么想法吗?

【问题讨论】:

  • 你有几节课?
  • 我有 5 节课。
  • 那你为什么有16个输出?
  • 您的标签和输出形状必须分别为[batch_size][batch_size, n_classes]

标签: pytorch


【解决方案1】:

您的标签和输出形状必须分别为 [batch_size][batch_size, n_classes]

【讨论】:

  • @user3062301 不客气。你能支持我的回答吗?
猜你喜欢
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 2021-11-18
  • 2012-04-08
  • 2019-06-13
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多