예제 #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)
예제 #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))
예제 #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())
예제 #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)
예제 #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)
예제 #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))
예제 #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)