2021
04-25
04-25
pytorch tensor int型除法出现的问题
昨天晚上跑起来一个classification实验,今天发现训练loss在降,然而accuracy永远是0。。。直觉告诉我evaluation有问题然后发现自己写了个很愚蠢的bugaccuracy对应的tensor出来是int型的,我用到了一个除法取平均。而pytorch里无论用/or//结果都是取整,,accuracy一直就没有。。所以转换成float就没问题了,,低级bug,下不为例补充:pytorchtensordivision/除法除法的时候要注意数据类型的问题a=torch.div(torch.tensor...
继续阅读 >
TypeError:cannotconcatenate'str'and'int'objectsprintstr+int的时候就会这样了python+作为连接符的时候,不会自动给你把int转换成str补充知识:TypeError:cannotconcatenate'str'and'list'objects和Python读取和保存图片运行程序时报错,然后我将list转化为str就好了。利用''.join(list)如果需要用逗号隔开,如1,2,3,4则使用','.join(list)Python中plt可以显示和保存图片,不能使用mpingimportmatplotlib.ima...
代码实例如下publicstaticvoidmain(String[]args){Integeri=10;Integerj=10;System.out.println(i==j);Integera=128;Integerb=128;System.out.println(a==b);intk=10;System.out.println(k==i);intkk=128;System.out.println(kk==a);Integerm=newInteger(10);Integern=newInteger(10);System.out.println(m==n);}我们使用反编译工具Jad,得到的...