Skip to content

Commit

Permalink
ClassErrorMeter has issue with batchsize=1 (pytorch#97)
Browse files Browse the repository at this point in the history
* Proposed fix of ClassErrorMeter to avoid issue with batchsize=1. The use of squeeze
is problematic. A new test was added to illustrate this in test_meters.py
  • Loading branch information
haim-barad authored and Sasha Sax committed Jul 26, 2018
1 parent ad81dab commit e390381
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/test_meters.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ def testClassErrorMeter(self):
err = mtr.value()
self.assertEqual(err, [50.0], "Half should be correct")

def testClassErrorMeteri_batch1(self):
mtr = meter.ClassErrorMeter(topk=[1])
output = torch.tensor([1, 0, 0])
if hasattr(torch, "arange"):
target = torch.arange(0, 1)
else:
target = torch.range(0, 0)
mtr.add(output, target)
err = mtr.value()
self.assertEqual(err, [0], "All should be correct")

def testConfusionMeter(self):
mtr = meter.ConfusionMeter(k=3)

Expand Down

0 comments on commit e390381

Please sign in to comment.