Beispiel #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)
Beispiel #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))
Beispiel #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())
Beispiel #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)
Beispiel #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)
Beispiel #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))
Beispiel #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)