1.Target 1 is out of bounds.
,(1)分类问题中,dataset里数据处理后,label的范围必须是[0,class_num-1]
,这里的label会作为损失函数的target。(换一种说法,假如对图片分类的结果有3种,cat、dog、bird,那么label也即loss_func的target的范围必须是[0,1,2]
)。注:nn.NLLoss貌似有一样的问题?(2)检查网络结构,最后一层的输出有几个
2.Using a target size (torch.Size([32])) that is different to the input size (torch.Size([32, 1])) is deprecated. Please ensure they have the same size.
,这个问题我在二分类问题中遇到的,损失函数的target是一维的,但是model的输出也即损失函数的input是二维的。
3.使用CrossEntropyLoss
函数,我们的模型里面的最后一层全连接层的输出一般大于1,这时候dataset里的label必须是一个一维的LongTensor类型,不然会在下面进行训练时计算loss的时候报错1D target tensor expected, multi-target not supported
;
4.expected scalar type Long but found Float
,这个通样是在dataset定义的时候出现的,dataset的label的应该是一个一维tensor(如第3条所说),比如我是对数字分类,label就是1,2,3…等具体的数字,在训练的时候,使用CrossEntropyLoss
函数的时候它会将一维的tensor转换成one-hot进行计算损失。