pytorch挖坑之:Expected object of scalar type Long but got scalar type Float for argument target...

1. 问题分析

报错提示:需要Long类型的,但是收到了Float类型。

google了一下,都说是到相应的位置,后面加上.float()。

但是改了之后,还是不行,报了另外一个错误:
pytorch挖坑之:Expected object of scalar type Long but got scalar type Float for argument target...后来发现,应该是自己传的target有问题,也就是label。

查看了一下自己写的Dataset类,手动地把0变成[1, 0], 把1变成[0, 1],
pytorch挖坑之:Expected object of scalar type Long but got scalar type Float for argument target...
**其实根本不需要!!!不需要!!!不需要!!!

虽然设置的输出有两个维度,但是这里的label就是1-D的就可以了。修改后,如下:
pytorch挖坑之:Expected object of scalar type Long but got scalar type Float for argument target...

2. 总结

没啥好总结的。再见

结束。