diff --git a/.github/workflows/docs-check.yml b/.github/workflows/docs-check.yml index c471c9aade7..8f8657b1c7c 100644 --- a/.github/workflows/docs-check.yml +++ b/.github/workflows/docs-check.yml @@ -26,8 +26,8 @@ jobs: - name: Install dependencies run: | - pip install -r requirements.txt -U -f https://download.pytorch.org/whl/cpu/torch_stable.html -q --use-feature=2020-resolver - pip install -r requirements/docs.txt --use-feature=2020-resolver + pip install -r requirements.txt -U -f https://download.pytorch.org/whl/cpu/torch_stable.html -q + pip install -r requirements/docs.txt python --version ; pip --version ; pip list shell: bash @@ -62,8 +62,8 @@ jobs: - name: Install dependencies run: | - pip install -r requirements.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q --use-feature=2020-resolver - pip install -r requirements/docs.txt --use-feature=2020-resolver + pip install -r requirements.txt -U -f https://download.pytorch.org/whl/torch_stable.html -q + pip install -r requirements/docs.txt # install Texlive, see https://linuxconfig.org/how-to-install-latex-on-ubuntu-20-04-focal-fossa-linux sudo apt-get update sudo apt-get install -y texlive-latex-extra dvipng texlive-pictures diff --git a/torchmetrics/functional/classification/jaccard.py b/torchmetrics/functional/classification/jaccard.py index 160d3eb47e9..4f9b9c2400e 100644 --- a/torchmetrics/functional/classification/jaccard.py +++ b/torchmetrics/functional/classification/jaccard.py @@ -72,21 +72,23 @@ def _jaccard_from_confmat( ] ) return scores - elif average == "macro": + + if average == "macro": scores = _jaccard_from_confmat( confmat, num_classes, average="none", ignore_index=ignore_index, absent_score=absent_score ) return torch.mean(scores) - elif average == "micro": + + if average == "micro": intersection = torch.sum(torch.diag(confmat)) union = torch.sum(torch.sum(confmat, dim=1) + torch.sum(confmat, dim=0) - torch.diag(confmat)) return intersection.float() / union.float() - else: - weights = torch.sum(confmat, dim=1).float() / torch.sum(confmat).float() - scores = _jaccard_from_confmat( - confmat, num_classes, average="none", ignore_index=ignore_index, absent_score=absent_score - ) - return torch.sum(weights * scores) + + weights = torch.sum(confmat, dim=1).float() / torch.sum(confmat).float() + scores = _jaccard_from_confmat( + confmat, num_classes, average="none", ignore_index=ignore_index, absent_score=absent_score + ) + return torch.sum(weights * scores) def jaccard_index(