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

2765 단어 예외 처리

질문:


RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #2 ‘mat2’

예외 코드 행:


prediction = net.forward(b_x)

해결 방법:


코드 앞에 줄을 추가하여 입력한 데이터를 dtype=torch로 변환합니다.float32의.
b_x = torch.tensor(b_x, dtype=torch.float32) prediction = net.forward(b_x)

참조 링크


https://github.com/pytorch/pytorch/issues/2138、
https://pytorch.org/docs/stable/tensors.html?highlight=float#torch.Tensor.float
# if you use the DataLoader you can avoid any miscommunication regarding built-in data structures for ATen

X = torch.from_numpy(X).double()
y = torch.from_numpy(y).double()

train_data = torch.utils.data.TensorDataset(X, y)
train_loader = torch.utils.data.DataLoader(train_data, batch_size=batch_size, shuffle=True)

X = Variable(X).float()
y = Variable(y).type(torch.LongTensor)

고맙습니다.


끝나다

좋은 웹페이지 즐겨찾기