Example #1
0
    def test_create_class_histograms_fail(self):
        pred_probs = self._get_base_pred_probs()
        targets = self._get_base_targets()

        # Torch tensors only
        with self.assertRaises(AssertionError):
            class_hist, total_hist = util.create_class_histograms(
                pred_probs.numpy(), targets, 20
            )

        # Torch tensors only
        with self.assertRaises(AssertionError):
            class_hist, total_hist = util.create_class_histograms(
                pred_probs, targets.numpy(), 20
            )

        # Prediction and target are same size
        with self.assertRaises(AssertionError):
            class_hist, total_hist = util.create_class_histograms(
                pred_probs[0:5, :], targets, 20
            )

        # Prediction is between 0 and 1
        with self.assertRaises(AssertionError):
            pred_probs[0, :] = torch.tensor([-0.1, 1.1])
            class_hist, total_hist = util.create_class_histograms(
                pred_probs, targets, 20
            )
Example #2
0
    def test_create_class_histograms_success(self):
        pred_probs = self._get_base_pred_probs()
        targets = self._get_base_targets()

        class_hist, total_hist = util.create_class_histograms(pred_probs, targets, 20)
        torch.testing.assert_allclose(class_hist, self._get_base_class_hist())
        torch.testing.assert_allclose(total_hist, self._get_base_total_hist())