Pytorch: Convert FloatTensor into DoubleTensor

前端 未结 2 1966
鱼传尺愫
鱼传尺愫 2021-02-07 20:55

I have 2 numpy arrays, which I convert into tensors to use the TensorDataset object.

import torch.utils.data as data_utils

X = np.zeros((100,30))
Y = np.zeros         


        
2条回答
  •  失恋的感觉
    2021-02-07 21:15

    This is because in PyTorch, you can not do operations between Tensor of different types. Your data is DoubleTensor, but the model parameter are FloatTensor. So you get this error message. As @mexmex have said, convert data to FloatTensor to make it conform with the model parameter type.

    Do not do the other way around! Trying to convert the model to double is greatly discouraged by PyTorch devs as GPUs are not good at double precision computation. Also, floating point is pretty enough for deep learning.

提交回复
热议问题