예제 #1
0
 def __call__(self, prediction: torch.Tensor,
              target: torch.Tensor) -> torch.Tensor:
     """
     Args:
         prediction: Network output.
             Dimensions - (Batch, Class, Depth, Height, Width)
         target: Target values. The classes should be ont-hot encoded.
             Dimensions - (Batch, Class, Depth, Height, Width)
     Returns:
         torch.Tensor: Recall score for each class averaged
             across the whole batch
     """
     return F.recall(prediction, target, self.epsilon)
예제 #2
0
 def test_if_returns_expected_values(self, images, target, result):
     assert np.isclose(F.recall(images.unsqueeze(dim=CHANNEL_DIM),
                                target.unsqueeze(dim=CHANNEL_DIM)),
                       result,
                       atol=1.e-3)
예제 #3
0
 def test_if_returns_0_for_worst_fit(self):
     images = torch.zeros(*BATCH_DIMS)
     target = torch.ones(*BATCH_DIMS)
     assert np.isclose(F.recall(images, target), 0, atol=1.e-4)
예제 #4
0
 def test_if_returns_1_for_perfect_fit(self):
     images = torch.ones(*BATCH_DIMS)
     target = torch.ones(*BATCH_DIMS)
     assert np.isclose(F.recall(images, target), 1, atol=1.e-4)
예제 #5
0
 def test_if_returns_expected_value_for_multiclass(self, images, target,
                                                   classes, result):
     images = images.unsqueeze(dim=CHANNEL_DIM).repeat(1, classes, 1)
     target = target.unsqueeze(dim=CHANNEL_DIM).repeat(1, classes, 1)
     result = [result for _ in range(classes)]
     assert np.all(np.isclose(F.recall(images, target), result, atol=1.e-3))
예제 #6
0
 def test_if_returns_correct_number_of_classes(self, input_shape, result):
     images = torch.ones(*input_shape)
     target = torch.ones(*input_shape)
     assert len(F.recall(images, target)) == result