RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 'weight'

numpy uses float64 as their default type, so call float() on these tensors before passing them to the TensorDataset:

inputs = torch.from_numpy(inputs_T),float()
targets = torch.from_numpy(targets_T).float()

(or cast them using numpy’s astype before).

15 Likes