Skip to content

Commit 77cb020

Browse files
authored
fix accuracy equals 0.0 bug
corrects/batch.batch_size * 100.0 always equals 0.0
1 parent 229ec8f commit 77cb020

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

train.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def train(train_iter, dev_iter, model, args):
2929
steps += 1
3030
if steps % args.log_interval == 0:
3131
corrects = (torch.max(logit, 1)[1].view(target.size()).data == target.data).sum()
32-
accuracy = corrects/batch.batch_size * 100.0
32+
accuracy = 100.0 * corrects/batch.batch_size
3333
sys.stdout.write(
3434
'\rBatch[{}] - loss: {:.6f} acc: {:.4f}%({}/{})'.format(steps,
3535
loss.data[0],
@@ -63,7 +63,7 @@ def eval(data_iter, model, args):
6363

6464
size = len(data_iter.dataset)
6565
avg_loss = loss.data[0]/size
66-
accuracy = corrects/size * 100.0
66+
accuracy = 100.0 * corrects/size
6767
model.train()
6868
print('\nEvaluation - loss: {:.6f} acc: {:.4f}%({}/{}) \n'.format(avg_loss,
6969
accuracy,

0 commit comments

Comments
 (0)