From 3b4bf335cd64a6c5a64ac8e8743b559431e79c9b Mon Sep 17 00:00:00 2001 From: Jirka Borovec Date: Wed, 25 May 2022 12:27:02 +0200 Subject: [PATCH 1/2] if/return --- .../functional/classification/jaccard.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/torchmetrics/functional/classification/jaccard.py b/torchmetrics/functional/classification/jaccard.py index 722adcd5e59..9dfef0474e7 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) / torch.sum(confmat) - 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) / torch.sum(confmat) + 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( From 567f0ea128ad0122bbe2d9d1470e2cad3928c080 Mon Sep 17 00:00:00 2001 From: Jirka Date: Wed, 25 May 2022 12:42:03 +0200 Subject: [PATCH 2/2] ci: drop pip 2020-resolver --- .github/workflows/docs-check.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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