pytorch神经网络的小问题

  1. UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).

     feature = torch.tensor(torch.from_numpy(feature), dtype=torch.float32)
    

改为:

feature = torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)
  1. RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 ‘mat1’ in call to _th_addmm

解决方法:

feature = torch.tensor(torch.from_numpy(feature))加上, dtype=torch.float32
feature = torch.as_tensor(torch.from_numpy(feature), dtype=torch.float32)

或者

#在代码前添加一行,将输入的数据转成是dtype=torch.float32的。
    #X= torch.tensor(X, dtype=torch.float32)
    output = net(X)

3.TypeError: ‘int’ object is not callable

	  2 batch_size = 64
----> 3 train_dataset = TensorDataset(x_train, y_train1,y_train2)
      4 test_dataset = TensorDataset(x_test, y_test1,y_test2)
      5 train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, shuffle=True)

出现这样的原因是因为,我在上面处理数据的时候,把转换为tensor放在了归一化前面,当然根本上不是顺序的原因。根本上是TensorDataset需要tensor。

你可能感兴趣的:(Pytorch深度学习,深度学习)