def test_functional_threshold(self): threshold = -0.5 actual = bin_acc(self.predictions, self.targets, threshold=threshold) label_predictions = (self.predictions > threshold).float() self.assertEqual((), actual.shape) np.testing.assert_almost_equal( (label_predictions == self.targets).float().mean() * 100, actual)
def test_functional_none(self): actual = bin_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 = bin_acc(self.predictions.cuda(), self.targets.cuda()) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.binary_accuracy, actual.cpu())
def test_functional_sum(self): actual = bin_acc(self.predictions, self.targets, reduction='sum') self.assertEqual((), actual.shape) np.testing.assert_almost_equal( (self.label_predictions == self.targets).float().sum() * 100, actual)
def test_functional(self): actual = bin_acc(self.predictions, self.targets) self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.binary_accuracy, actual)
def test_functional_none(self): actual = bin_acc(self.predictions, self.targets, reduction='none') self.assertEqual(self.targets.shape, actual.shape) self.assertTrue(torch.all(self.binary_accuracy_none == actual))
def test_functional_sum(self): actual = bin_acc(self.predictions, self.targets, reduction='sum') self.assertEqual((), actual.shape) np.testing.assert_almost_equal(self.binary_accuracy_none.sum(), actual)