Problem description:
This error occurs when LSTM is used for data training, I convert the numpy data directly to the tensor data type in the torch:
RuntimeError: expected scalar type Double but found Float
Cause analysis:
The data type of the tensor is incorrect
x_train_tensor = torch.from_numpy(x_train)
y_train_tensor = torch.from_numpy(y_train)
Solution:
Convert the original tensor to the torch.float32 type
x_train_tensor = torch.from_numpy(x_train).to(torch.float32)
y_train_tensor = torch.from_numpy(y_train).to(torch.float32)
Read More:
- Pytorch Error: runtimeerror: expected scalar type double but found float
- [Solved] Runtime error: expected scalar type Float but found Double
- [Solved] RuntimeError: expected scalar type Long but found Float
- Pytorch Error: RuntimeError: value cannot be converted to type float without overflow: (0.00655336,-0.00
- How to Solve RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu
- Autograd error in Python: runtimeerror: grad can be implicitly created only for scalar outputs
- [Solved] RuntimeError: scatter(): Expected dtype int64 for index
- [Solved] RuntimeError : PyTorch was compiled without NumPy support
- can‘t multiply sequence by non-int of type ‘numpy.float64‘
- [Solved] RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- [Solved] RuntimeError: gather(): Expected dtype int64 for index
- [Pytorch Error Solution] Pytorch distributed RuntimeError: Address already in use
- [Solved] PyTorch Caught RuntimeError in DataLoader worker process 0和invalid argument 0: Sizes of tensors mus
- [Solved] Pytorch Tensor to numpy error: RuntimeError: Can‘t call numpy() on Tensor that requires grad.报错
- [Solved] Pytorch error: RuntimeError: one of the variables needed for gradient computation
- pytorch: RuntimeError CUDA error device-side assert triggered
- [Solved] Pytorch Error: RuntimeError: Error(s) in loading state_dict for Network: size mismatch
- [Solved] pytorch loss.backward() Error: RuntimeError: Function AddBackward0 returned an invalid gradient at index 1…
- Pytorch torch.cuda.FloatTensor Error: RuntimeError: one of the variables needed for gradient computation has…