Skip to content

Commit 7b35173

Browse files
nelson-liuchsasank
authored andcommitted
Fix loss calculation in transfer learning tutorial (pytorch#187)
* Fix loss calculation in transfer learning tutorial * Multiply batch loss by batch size to get sum loss
1 parent b758e3c commit 7b35173

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

beginner_source/transfer_learning_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def train_model(model, criterion, optimizer, scheduler, num_epochs=25):
189189
optimizer.step()
190190

191191
# statistics
192-
running_loss += loss.data[0]
192+
running_loss += loss.data[0] * inputs.size(0)
193193
running_corrects += torch.sum(preds == labels.data)
194194

195195
epoch_loss = running_loss / dataset_sizes[phase]

0 commit comments

Comments
 (0)