Skip to content

Commit

Permalink
Use tensor.item() instead of tensor.data[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhkhuc committed Oct 6, 2018
1 parent b15c5b1 commit 9afc6a7
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 2_logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def train(model, loss, optimizer, x_val, y_val):
# Update parameters
optimizer.step()

return output.data[0]
return output.item()


def predict(model, x_val):
Expand Down
2 changes: 1 addition & 1 deletion 3_neural_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def train(model, loss, optimizer, x_val, y_val):
# Update parameters
optimizer.step()

return output.data[0]
return output.item()


def predict(model, x_val):
Expand Down
2 changes: 1 addition & 1 deletion 4_modern_neural_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def train(model, loss, optimizer, x_val, y_val):
# Update parameters
optimizer.step()

return output.data[0]
return output.item()


def predict(model, x_val):
Expand Down
2 changes: 1 addition & 1 deletion 5_convolutional_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def train(model, loss, optimizer, x_val, y_val):
# Update parameters
optimizer.step()

return output.data[0]
return output.item()


def predict(model, x_val):
Expand Down
2 changes: 1 addition & 1 deletion 6_lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def train(model, loss, optimizer, x_val, y_val):
# Update parameters
optimizer.step()

return output.data[0]
return output.item()


def predict(model, x_val):
Expand Down

0 comments on commit 9afc6a7

Please sign in to comment.