TypeError: kl_div(): argument ‘target‘ (position 2) must be Tensor, not numpy.int64

问题描述
File “D:/python/modelsmy/trainvgg16.py”, line 77, in
train(net, train_dataSet, df_train, test_dataSet, df_test, optimizer, device, num_epochs)
File “D:/python/modelsmy/trainvgg16.py”, line 34, in train
l = loss(y_hat, y)

TypeError: kl_div(): argument ‘target’ (position 2) must be Tensor, not numpy.int64

解决方案
y = torch.tensor(y)

又报错
RuntimeError: log_vml_cpu not implemented for ‘Long’
解决
y = torch.tensor(y, dtype=float)

你可能感兴趣的:(TypeError: kl_div(): argument ‘target‘ (position 2) must be Tensor, not numpy.int64)