Skip to content

Commit

Permalink
Merge pull request #15 from elliottzheng/master
Browse files Browse the repository at this point in the history
fix:In pytorch 0.4 accuracy always zero
  • Loading branch information
fxia22 authored Jun 2, 2018
2 parents 3700c44 + 27d3413 commit 75dd61c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions train_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
optimizer.step()
pred_choice = pred.data.max(1)[1]
correct = pred_choice.eq(target.data).cpu().sum()
print('[%d: %d/%d] train loss: %f accuracy: %f' %(epoch, i, num_batch, loss.data[0], correct/float(opt.batchSize)))
print('[%d: %d/%d] train loss: %f accuracy: %f' %(epoch, i, num_batch, loss.item(),correct.item() / float(opt.batchSize)))

if i % 10 == 0:
j, data = next(enumerate(testdataloader, 0))
Expand All @@ -92,6 +92,6 @@
loss = F.nll_loss(pred, target)
pred_choice = pred.data.max(1)[1]
correct = pred_choice.eq(target.data).cpu().sum()
print('[%d: %d/%d] %s loss: %f accuracy: %f' %(epoch, i, num_batch, blue('test'), loss.data[0], correct/float(opt.batchSize)))
print('[%d: %d/%d] %s loss: %f accuracy: %f' %(epoch, i, num_batch, blue('test'), loss.item(), correct.item()/float(opt.batchSize)))

torch.save(classifier.state_dict(), '%s/cls_model_%d.pth' % (opt.outf, epoch))
4 changes: 2 additions & 2 deletions train_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
optimizer.step()
pred_choice = pred.data.max(1)[1]
correct = pred_choice.eq(target.data).cpu().sum()
print('[%d: %d/%d] train loss: %f accuracy: %f' %(epoch, i, num_batch, loss.data[0], correct/float(opt.batchSize * 2500)))
print('[%d: %d/%d] train loss: %f accuracy: %f' %(epoch, i, num_batch, loss.item(), correct.item()/float(opt.batchSize * 2500)))

if i % 10 == 0:
j, data = next(enumerate(testdataloader, 0))
Expand All @@ -95,6 +95,6 @@
loss = F.nll_loss(pred, target)
pred_choice = pred.data.max(1)[1]
correct = pred_choice.eq(target.data).cpu().sum()
print('[%d: %d/%d] %s loss: %f accuracy: %f' %(epoch, i, num_batch, blue('test'), loss.data[0], correct/float(opt.batchSize * 2500)))
print('[%d: %d/%d] %s loss: %f accuracy: %f' %(epoch, i, num_batch, blue('test'), loss.item(), correct.item()/float(opt.batchSize * 2500)))

torch.save(classifier.state_dict(), '%s/seg_model_%d.pth' % (opt.outf, epoch))

0 comments on commit 75dd61c

Please sign in to comment.