---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_2828\2342855618.py in <module>
21 predicted = torch.max(putputs.data,1)
22 total += labels.size(0)
---> 23 correct += predicted.eq(labels.data).cpu().sum()
24 print('[epoch:%d,iter:%d] loss: %0.3f | Acc: %.3f%%' %(epoch + 1,(i + 1 + epoch * length ),sum_loss/(i + 1),100.*correct/total))
AttributeError: 'torch.return_types.max' object has no attribute 'eq'
我在网站上读过torch.max()的解释,但它仍然不能解决在这里输入图像描述的问题
发布于 2022-11-17 07:20:08
torch.max
返回一个命名的元组。如果您只对最大值感兴趣,可以这样做:
predicted = torch.max(putputs.data,1).values
如果需要最大值的索引,可以使用:
predicted = torch.max(putputs.data,1).indices
https://stackoverflow.com/questions/74445444
复制相似问题