Skip to content

Commit

Permalink
Use "reduction='elementwise_mean'" instead of "size_average=True"
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhkhuc committed Oct 6, 2018
1 parent 9afc6a7 commit 03b7ecf
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 @@ -52,7 +52,7 @@ def main():
n_examples, n_features = trX.size()
n_classes = 10
model = build_model(n_features, n_classes)
loss = torch.nn.CrossEntropyLoss(size_average=True)
loss = torch.nn.CrossEntropyLoss(reduction='elementwise_mean')
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
batch_size = 100

Expand Down
2 changes: 1 addition & 1 deletion 3_neural_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def main():
n_examples, n_features = trX.size()
n_classes = 10
model = build_model(n_features, n_classes)
loss = torch.nn.CrossEntropyLoss(size_average=True)
loss = torch.nn.CrossEntropyLoss(reduction='elementwise_mean')
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
batch_size = 100

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 @@ -55,7 +55,7 @@ def main():
n_examples, n_features = trX.size()
n_classes = 10
model = build_model(n_features, n_classes)
loss = torch.nn.CrossEntropyLoss(size_average=True)
loss = torch.nn.CrossEntropyLoss(reduction='elementwise_mean')
optimizer = optim.Adam(model.parameters())
batch_size = 100

Expand Down
2 changes: 1 addition & 1 deletion 5_convolutional_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def main():
n_examples = len(trX)
n_classes = 10
model = ConvNet(output_dim=n_classes)
loss = torch.nn.CrossEntropyLoss(size_average=True)
loss = torch.nn.CrossEntropyLoss(reduction='elementwise_mean')
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
batch_size = 100

Expand Down
2 changes: 1 addition & 1 deletion 6_lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main():
trY = torch.from_numpy(trY).long()

model = LSTMNet(input_dim, hidden_dim, n_classes)
loss = torch.nn.CrossEntropyLoss(size_average=True)
loss = torch.nn.CrossEntropyLoss(reduction='elementwise_mean')
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)

for i in range(epochs):
Expand Down

0 comments on commit 03b7ecf

Please sign in to comment.