1.pytorch报错:
报错内容如下:
Expected object of scalar type Long but got scalar type Double for argument #2 'target'
表示第二个位置的参数要求是Long类型,然而传入的时候是Double类型,因此我们只需:
即可。
2. 如果会继续出现报错:
RuntimeError: multi-target not supported at /opt/conda/conda-bld/pytorch_1556653099582/work/aten/src/THCUNN/generic/:15
表示在计算loss过程中遇到了多输出预测值。或者标签的维度是不同的(我这边标签的shape是(128, 1)),我们只需要将标签squeeze就行,具体参考torch.squeeze()函数,个人变动方法:
3.总结:torch中数据类型的变化:
torch数据类型转换
数据类型 | 数据长度 | 用法 |
int | int32 | () |
long | int64 | torch.long() |
float | float32 | torch.float() |
double | float64 | torch.double() |
至于需要哪种变化,各位看官,请便。。。
















