def test_functional_none(self): actual = acc(self.predictions, self.targets, reduction='none') self.assertEqual(self.targets.shape, actual.shape) self.assertTrue( torch.all( 100. * (self.label_predictions == self.targets).float() == actual))
def test_functional_on_gpu(self): actual = acc(self.predictions.cuda(), self.targets.cuda()) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.accuracy, actual.cpu())
def test_functional_sum(self): actual = acc(self.predictions, self.targets, reduction='sum') self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.accuracy * len(self.predictions), actual)
def test_functional(self): actual = acc(self.predictions, self.targets) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.accuracy, actual)
def test_functional_ignore_index_with_valid_index(self): actual = acc(self.predictions, self.targets, ignore_index=1) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(20., actual)
def test_functional_ignore_index_with_different_value(self): actual = acc(self.predictions, self.targets, ignore_index=-1) self.assertEqual((), actual.shape) self.assertAlmostEqual(1 / 3 * 100, float(actual), places=5)
def test_functional_none(self): actual = acc(self.predictions, self.targets, reduction='none') self.assertEqual(self.targets.shape, actual.shape) self.assertTrue(torch.all(self.accuracy_none == actual))