Example #1
0
 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)
Example #2
0
 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))
Example #3
0
 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())
Example #4
0
 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)
Example #5
0
 def test_functional(self):
     actual = bin_acc(self.predictions, self.targets)
     self.assertEqual((), actual.shape)
     np.testing.assert_almost_equal(self.binary_accuracy, actual)
Example #6
0
 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))
Example #7
0
 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)