绘制混淆矩阵

混淆矩阵

(1)输出混淆矩阵:
教程https://blog.csdn.net/shanshangyouzhiyangM/article/details/84943011
AverageMeter()报错,直接复制https://blog.csdn.net/rytyy/article/details/105944813里的类过去。
torchnet包安装https://blog.csdn.net/qq_44125896/article/details/105498046,直接放到代码文件目录下。
1)报错:AssertionError: number of predictions does not match size of confusion matrix
在这里插入图片描述
搞不定。
换成sklearn里面的混淆矩阵吧。
https://blog.csdn.net/SartinL/article/details/105844832
2)报错:TypeError: can’t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
在这里插入图片描述
加.cpu().numpy
3)报错:RuntimeError: Can’t call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.

https://blog.csdn.net/weixin_38424903/article/details/107649436变成.detach().cpu().numpy
不报错了。

4)出现ValueError: Classification metrics can’t handle a mix of binary and continuous-multioutput targets错误。
输出预测和标签的类型
在这里插入图片描述
输出结果类型是ndarray
<class ‘torch.Tensor’>
<class ‘numpy.ndarray’>
<class ‘torch.Tensor’>
<class ‘numpy.ndarray’>
混淆矩阵,正常应该是list
<class ‘list’>
<class ‘list’>
类型。
https://blog.csdn.net/qq_39355550/article/details/81774469变成list类型。
在这里插入图片描述
5)类型不一致
ValueError: Classification metrics can’t handle a mix of binary and continuous-multioutput targets
输出预测list中最大的值。
https://blog.csdn.net/EricHenry/article/details/105200883
所以要输出嵌套列表每一个小列表的最大值。

6)还是报错ValueError: Classification metrics can’t handle a mix of binary and continuous-multioutput targets
应该是输出小列表最大值对应的索引值
成功
在这里插入图片描述

7)保存热力图
https://blog.csdn.net/kane7csdn/article/details/83756583
https://blog.csdn.net/kane7csdn/article/details/83756583
发现残留上一次训练损失的图像,https://blog.csdn.net/qq_39560620/article/details/105643125,在plt.savefig()后面加上plt.close()就可以了。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值