def test_fbeta_score(pred, target, beta, exp_score): score = fbeta_score(torch.tensor(pred), torch.tensor(target), beta, reduction='none') assert torch.allclose(score, torch.tensor(exp_score)) score = fbeta_score(to_onehot(torch.tensor(pred)), torch.tensor(target), beta, reduction='none') assert torch.allclose(score, torch.tensor(exp_score))
def test_tbd_remove_in_v1_2_0_metrics(): from pytorch_lightning.metrics.classification import Fbeta from pytorch_lightning.metrics.functional.classification import f1_score, fbeta_score with pytest.deprecated_call(match='will be removed in v1.2'): Fbeta(2) with pytest.deprecated_call(match='will be removed in v1.2'): fbeta_score(torch.tensor([0, 1, 2, 3]), torch.tensor([0, 1, 2, 1]), 0.2) with pytest.deprecated_call(match='will be removed in v1.2'): f1_score(torch.tensor([0, 1, 0, 1]), torch.tensor([0, 1, 0, 0]))
def forward(self, pred: torch.Tensor, target: torch.Tensor) -> torch.Tensor: """ Actual metric computation Args: pred: predicted labels target: groundtruth labels Return: torch.Tensor: classification score """ return fbeta_score(pred=pred, target=target, beta=self.beta, num_classes=self.num_classes, reduction=self.reduction)