Fix requires_grad=True needs float tensor

This commit is contained in:
TimHo
2018-08-05 23:59:17 +08:00
parent 9219526869
commit 2bfebb0a4a

View File

@ -23,9 +23,9 @@ import torchvision.transforms as transforms
# ================================================================== # # ================================================================== #
# Create tensors. # Create tensors.
x = torch.tensor(1, requires_grad=True) x = torch.tensor(1., requires_grad=True)
w = torch.tensor(2, requires_grad=True) w = torch.tensor(2., requires_grad=True)
b = torch.tensor(3, requires_grad=True) b = torch.tensor(3., requires_grad=True)
# Build a computational graph. # Build a computational graph.
y = w * x + b # y = 2 * x + 3 y = w * x + b # y = 2 * x + 3