python代码总是出现pytorch训练过程训练集精度为0的情况的解决

版权声明:主要是自己学习,别人如果有用,我很开心,人、虽然一般只有我自己看得懂。。。。。 https://blog.csdn.net/qq_27292549/article/details/82216877

原因是gao的代码是pytorch3迁移过来的,很多地方使用了sum(pred_y== target)来求训练集的精度,但是没有转成numpy这里就会为0,因为torch数据本身不支持这种计算方式,所以改成sum(np.array(pred_y)== np.array(target.data.cpu()))即可使训练集正常运行

猜你喜欢

转载自blog.csdn.net/qq_27292549/article/details/82216877