예제 #1
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.f_score(images, target, 1), result, atol=1.e-3))
예제 #2
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: F Score for each class averaged
             across the whole batch
     """
     return F.f_score(prediction, target, self.beta, self.epsilon)
예제 #3
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.f_score(images, target, 1)) == result
예제 #4
0
 def test_if_f2_returns_expected_values(self, images, target, result):
     assert np.isclose(F.f_score(images.unsqueeze(dim=CHANNEL_DIM),
                                 target.unsqueeze(dim=CHANNEL_DIM),
                                 beta=2),
                       result,
                       atol=1.e-3)
예제 #5
0
 def test_if_returns_0_for_worst_fit(self):
     images = torch.zeros(*BATCH_DIMS)
     target = torch.ones(*BATCH_DIMS)
     assert np.isclose(F.f_score(images, target, beta=1), 0, atol=1.e-4)
예제 #6
0
 def test_if_returns_1_for_perfect_fit(self):
     images = torch.ones(*BATCH_DIMS)
     target = torch.ones(*BATCH_DIMS)
     assert np.isclose(F.f_score(images, target, beta=1), 1, atol=1.e-4)