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))
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())
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)
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)
def test_hundred(self): accuracy = Accuracy() actual = accuracy(self.predictions, self.label_predictions) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(100., actual)
def test_standard(self): accuracy = Accuracy() actual = accuracy(self.predictions, self.targets) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.accuracy, actual)
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)
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)
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))