Example #1
0
 def test_none_hundred(self):
     accuracy = Accuracy(reduction='none')
     actual = accuracy(self.predictions, self.label_predictions)
     self.assertEqual(self.targets.shape, actual.shape)
     self.assertTrue(
         torch.all(
             100. *
             torch.ones_like(self.label_predictions).float() == actual))
Example #2
0
 def test_on_gpu(self):
     accuracy = Accuracy()
     accuracy.cuda()
     actual = accuracy(self.predictions.cuda(), self.targets.cuda())
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.accuracy, actual.cpu())
Example #3
0
 def test_sum(self):
     accuracy = Accuracy(reduction='sum')
     actual = accuracy(self.predictions, self.targets)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.accuracy * len(self.predictions),
                                    actual)
Example #4
0
 def test_sum_hundred(self):
     accuracy = Accuracy(reduction='sum')
     actual = accuracy(self.predictions, self.label_predictions)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(100. * len(self.predictions), actual)
Example #5
0
 def test_hundred(self):
     accuracy = Accuracy()
     actual = accuracy(self.predictions, self.label_predictions)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(100., actual)
Example #6
0
 def test_standard(self):
     accuracy = Accuracy()
     actual = accuracy(self.predictions, self.targets)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.accuracy, actual)
Example #7
0
 def test_ignore_index_with_valid_index(self):
     accuracy = Accuracy(ignore_index=1)
     actual = accuracy(self.predictions, self.targets)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(20., actual)
Example #8
0
 def test_ignore_index_with_different_value(self):
     accuracy = Accuracy(ignore_index=-1)
     actual = accuracy(self.predictions, self.targets)
     self.assertEqual((), actual.shape)
     self.assertAlmostEqual(1 / 3 * 100, float(actual), places=5)
Example #9
0
 def test_none(self):
     accuracy = Accuracy(reduction='none')
     actual = accuracy(self.predictions, self.targets)
     self.assertEqual(self.targets.shape, actual.shape)
     self.assertTrue(torch.all(self.accuracy_none == actual))