流浪的歌手阿 2021-08-08 23:07 采纳率: 0%
浏览 291

pytorch测试集看每类准确率 class_correct[label] +=( c[i].item())报错

class_correct[label] +=( c[i].item())
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
就是网络上最常用的测试每类数据集准确率的代码

img

找到一个外网ds遇到相似问题的评论,
correct seems to be a 0-dim tensor, which you cannot index. This error might be raised, as you are calling np.squeeze to create correct.

有没有xd会改的

  • 写回答

2条回答 默认 最新

  • 关注

    应该是pytorch版本不同造成的,你降低下版本试试

    评论

报告相同问题?

问题事件

  • 创建了问题 8月8日