pytorch数据集中类型不匹配

pytorch中,出现的错误:

return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)

expected scalar type Long but found Float

错误位置:

l = loss(net(X), y)    # X是特征Tensor, y是labels_tensor, 计算损失函数,这里出错,y的数据类型不匹配,可以修改数据类型
修改方法:
train_labels_tensor = torch.Tensor(train_labels_df.values).to(dtype=torch.int64)
 

 

posted @ 2023-01-07 21:23  __sunshine  阅读(396)  评论(0)    收藏  举报