From 0d3494f195579863a661ce27ceb81356245e78ef Mon Sep 17 00:00:00 2001 From: ndrwrbgs <10776890+ndrwrbgs@users.noreply.github.com> Date: Tue, 19 Nov 2024 02:24:16 -0600 Subject: [PATCH 01/10] docs: Fix typo in error message (#2838) Fix error message Previous: "If `preds` have one dimension more than `target`, the shape of `preds` should at least 3D when multidim_average is set to `samplewise`" Now: "If `preds` have one dimension more than `target`, the shape of `preds` should be at least 3D when multidim_average is set to `samplewise`" --- src/torchmetrics/functional/classification/stat_scores.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/torchmetrics/functional/classification/stat_scores.py b/src/torchmetrics/functional/classification/stat_scores.py index e9d78b1a1b7..fbb6098db40 100644 --- a/src/torchmetrics/functional/classification/stat_scores.py +++ b/src/torchmetrics/functional/classification/stat_scores.py @@ -291,7 +291,7 @@ def _multiclass_stat_scores_tensor_validation( ) if multidim_average != "global" and preds.ndim < 3: raise ValueError( - "If `preds` have one dimension more than `target`, the shape of `preds` should " + "If `preds` have one dimension more than `target`, the shape of `preds` should be" " at least 3D when multidim_average is set to `samplewise`" ) @@ -303,7 +303,7 @@ def _multiclass_stat_scores_tensor_validation( ) if multidim_average != "global" and preds.ndim < 2: raise ValueError( - "When `preds` and `target` have the same shape, the shape of `preds` should " + "When `preds` and `target` have the same shape, the shape of `preds` should be" " at least 2D when multidim_average is set to `samplewise`" ) else: From 404d35003d460febe1520f77f223186e10c501ba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:50:12 +0100 Subject: [PATCH 02/10] build(deps): bump pytest-doctestplus from 1.2.1 to 1.3.0 in /requirements (#2843) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/_doctest.txt | 2 +- requirements/_tests.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/_doctest.txt b/requirements/_doctest.txt index 0d693aa8c18..6b1405d88da 100644 --- a/requirements/_doctest.txt +++ b/requirements/_doctest.txt @@ -2,5 +2,5 @@ # in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment pytest >=8.0, <9.0 -pytest-doctestplus >=1.0, <1.3 +pytest-doctestplus >=1.0, <1.4 pytest-rerunfailures >=13.0, <15.0 diff --git a/requirements/_tests.txt b/requirements/_tests.txt index 2126783a532..e12b841d915 100644 --- a/requirements/_tests.txt +++ b/requirements/_tests.txt @@ -6,7 +6,7 @@ coverage ==7.6.* codecov ==2.1.13 pytest ==8.3.* pytest-cov ==6.0.0 -pytest-doctestplus ==1.2.1 +pytest-doctestplus ==1.3.0 pytest-rerunfailures ==14.0 pytest-timeout ==2.3.1 pytest-xdist ==3.6.1 From d68a96b74662dd3db48e43053cc255fd9358b45d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:52:13 +0100 Subject: [PATCH 03/10] build(deps): bump lightning-utilities from 0.11.8 to 0.11.9 in /requirements (#2844) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/_docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/_docs.txt b/requirements/_docs.txt index 1fd1d103caf..d5f584c6e98 100644 --- a/requirements/_docs.txt +++ b/requirements/_docs.txt @@ -13,7 +13,7 @@ sphinx-autobuild ==2024.10.3 sphinx-gallery ==0.18.0 lightning >=1.8.0, <2.5.0 -lightning-utilities ==0.11.8 +lightning-utilities ==0.11.9 pydantic > 1.0.0, < 3.0.0 # integrations From d528131c8e7f130c65ba62a14e12f15906d488c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:55:42 +0100 Subject: [PATCH 04/10] build(deps): bump pytest-rerunfailures from 14.0 to 15.0 in /requirements (#2845) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/_doctest.txt | 2 +- requirements/_tests.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/_doctest.txt b/requirements/_doctest.txt index 6b1405d88da..442b477c8ad 100644 --- a/requirements/_doctest.txt +++ b/requirements/_doctest.txt @@ -3,4 +3,4 @@ pytest >=8.0, <9.0 pytest-doctestplus >=1.0, <1.4 -pytest-rerunfailures >=13.0, <15.0 +pytest-rerunfailures >=13.0, <16.0 diff --git a/requirements/_tests.txt b/requirements/_tests.txt index e12b841d915..0a8cb73eaab 100644 --- a/requirements/_tests.txt +++ b/requirements/_tests.txt @@ -7,7 +7,7 @@ codecov ==2.1.13 pytest ==8.3.* pytest-cov ==6.0.0 pytest-doctestplus ==1.3.0 -pytest-rerunfailures ==14.0 +pytest-rerunfailures ==15.0 pytest-timeout ==2.3.1 pytest-xdist ==3.6.1 phmdoctest ==1.4.0 From 02ad4c998de21d234d3d1ce7e8ae412c022993a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 09:18:34 +0100 Subject: [PATCH 05/10] build(deps): bump pypa/gh-action-pypi-publish from 1.11.0 to 1.12.2 (#2855) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/publish-pkg.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-pkg.yml b/.github/workflows/publish-pkg.yml index 490eeac9c15..af47477a480 100644 --- a/.github/workflows/publish-pkg.yml +++ b/.github/workflows/publish-pkg.yml @@ -67,7 +67,7 @@ jobs: - run: ls -lh dist/ # We do this, since failures on test.pypi aren't that bad - name: Publish to Test PyPI - uses: pypa/gh-action-pypi-publish@v1.11.0 + uses: pypa/gh-action-pypi-publish@v1.12.2 with: user: __token__ password: ${{ secrets.test_pypi_password }} @@ -94,7 +94,7 @@ jobs: path: dist - run: ls -lh dist/ - name: Publish distribution 📦 to PyPI - uses: pypa/gh-action-pypi-publish@v1.11.0 + uses: pypa/gh-action-pypi-publish@v1.12.2 with: user: __token__ password: ${{ secrets.pypi_password }} From 3437c5ad7ba85ebffbe23d171ceeafc1b23aba87 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:00:19 +0100 Subject: [PATCH 06/10] build(deps): bump codecov/codecov-action from 4 to 5 (#2853) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 4e79c632692..a2188c29b82 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -198,7 +198,7 @@ jobs: - name: Upload coverage to Codecov # skip for PR if there is nothing to test, note that outside PR there is default 'unittests' if: ${{ env.TEST_DIRS != '' }} - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} file: tests/coverage.xml From f1d8f531fc5cb1120fe463930f7cf909ee9c4617 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:30:17 +0100 Subject: [PATCH 07/10] build(deps): bump Lightning-AI/utilities from 0.11.8 to 0.11.9 (#2854) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com> --- .github/workflows/ci-checks.yml | 12 ++++++------ .github/workflows/clear-cache.yml | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci-checks.yml b/.github/workflows/ci-checks.yml index fa3eb8ccdee..dfb11884f8a 100644 --- a/.github/workflows/ci-checks.yml +++ b/.github/workflows/ci-checks.yml @@ -13,19 +13,19 @@ concurrency: jobs: check-code: - uses: Lightning-AI/utilities/.github/workflows/check-typing.yml@v0.11.8 + uses: Lightning-AI/utilities/.github/workflows/check-typing.yml@v0.11.9 with: - actions-ref: v0.11.8 + actions-ref: v0.11.9 extra-typing: "typing" check-schema: - uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@v0.11.8 + uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@v0.11.9 check-package: if: github.event.pull_request.draft == false - uses: Lightning-AI/utilities/.github/workflows/check-package.yml@v0.11.8 + uses: Lightning-AI/utilities/.github/workflows/check-package.yml@v0.11.9 with: - actions-ref: v0.11.8 + actions-ref: v0.11.9 artifact-name: dist-packages-${{ github.sha }} import-name: "torchmetrics" testing-matrix: | @@ -35,7 +35,7 @@ jobs: } check-md-links: - uses: Lightning-AI/utilities/.github/workflows/check-md-links.yml@v0.11.8 + uses: Lightning-AI/utilities/.github/workflows/check-md-links.yml@v0.11.9 with: base-branch: master config-file: ".github/markdown-links-config.json" diff --git a/.github/workflows/clear-cache.yml b/.github/workflows/clear-cache.yml index 057827d611c..71a77a340d4 100644 --- a/.github/workflows/clear-cache.yml +++ b/.github/workflows/clear-cache.yml @@ -23,18 +23,18 @@ on: jobs: cron-clear: if: github.event_name == 'schedule' || github.event_name == 'pull_request' - uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@v0.11.8 + uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@v0.11.9 with: - scripts-ref: v0.11.7 + scripts-ref: v0.11.9 dry-run: ${{ github.event_name == 'pull_request' }} pattern: "pip-latest" age-days: 7 direct-clear: if: github.event_name == 'workflow_dispatch' || github.event_name == 'pull_request' - uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@v0.11.8 + uses: Lightning-AI/utilities/.github/workflows/cleanup-caches.yml@v0.11.9 with: - scripts-ref: v0.11.8 + scripts-ref: v0.11.9 dry-run: ${{ github.event_name == 'pull_request' }} pattern: ${{ inputs.pattern || 'pypi_wheels' }} # setting str in case of PR / debugging age-days: ${{ fromJSON(inputs.age-days) || 0 }} # setting 0 in case of PR / debugging From cb1aa02af2ecd2f341a2c5480b32ccffe9717ea3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 10:11:15 +0900 Subject: [PATCH 08/10] build(deps): update transformers requirement from <4.47.0,>4.4.0 to >4.4.0,<4.48.0 in /requirements (#2864) build(deps): update transformers requirement in /requirements Updates the requirements on [transformers](https://github.com/huggingface/transformers) to permit the latest version. - [Release notes](https://github.com/huggingface/transformers/releases) - [Commits](https://github.com/huggingface/transformers/compare/v4.42.3...v4.47.0) --- updated-dependencies: - dependency-name: transformers dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/multimodal.txt | 2 +- requirements/text.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/multimodal.txt b/requirements/multimodal.txt index 2f5c6749bd9..4a0f286698d 100644 --- a/requirements/multimodal.txt +++ b/requirements/multimodal.txt @@ -1,5 +1,5 @@ # NOTE: the upper bound for the package version is only set for CI stability, and it is dropped while installing this package # in case you want to preserve/enforce restrictions on the latest compatible version, add "strict" as an in-line comment -transformers >=4.42.3, <4.47.0 +transformers >=4.42.3, <4.48.0 piq <=0.8.0 diff --git a/requirements/text.txt b/requirements/text.txt index a24ce0c6d16..68db81d9e33 100644 --- a/requirements/text.txt +++ b/requirements/text.txt @@ -4,7 +4,7 @@ nltk >3.8.1, <=3.9.1 tqdm <4.68.0 regex >=2021.9.24, <=2024.11.6 -transformers >4.4.0, <4.47.0 +transformers >4.4.0, <4.48.0 mecab-python3 >=1.0.6, <1.1.0 ipadic >=1.0.0, <1.1.0 sentencepiece >=0.2.0, <0.3.0 From a968ebe4af5b2174a19fc8b89ba9efac51717564 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:07:59 +0900 Subject: [PATCH 09/10] build(deps): update scikit-learn requirement from ==1.5.* to ==1.6.* in /requirements (#2862) build(deps): update scikit-learn requirement in /requirements Updates the requirements on [scikit-learn](https://github.com/scikit-learn/scikit-learn) to permit the latest version. - [Release notes](https://github.com/scikit-learn/scikit-learn/releases) - [Commits](https://github.com/scikit-learn/scikit-learn/compare/1.5.0rc1...1.6.0) --- updated-dependencies: - dependency-name: scikit-learn dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/_tests.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/_tests.txt b/requirements/_tests.txt index 0a8cb73eaab..32e3bd3a1ca 100644 --- a/requirements/_tests.txt +++ b/requirements/_tests.txt @@ -18,5 +18,5 @@ fire ==0.7.* cloudpickle >1.3, <=3.1.0 scikit-learn ==1.2.*; python_version < "3.9" -scikit-learn ==1.5.*; python_version > "3.8" # we do not use `> =` because of oldest replcement +scikit-learn ==1.6.*; python_version > "3.8" # we do not use `> =` because of oldest replcement cachier ==3.1.2 From cd24d2be0cb61342ed9e4bb87de92b6507b61d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20K=C3=A4nzig?= <36882833+nkaenzig@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:15:34 +0100 Subject: [PATCH 10/10] Fix issue with shared state of `MetricCollection` compute group when using `DiceScore(average="weighted")` (#2848) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nicki Skafte Detlefsen --- CHANGELOG.md | 2 +- src/torchmetrics/segmentation/dice.py | 3 +-- tests/unittests/segmentation/test_dice.py | 30 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a253f90f6ef..444ab2b12e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- +- Fixed issue with shared state in metric collection when using dice score ([#2848](https://github.com/PyTorchLightning/metrics/pull/2848)) --- diff --git a/src/torchmetrics/segmentation/dice.py b/src/torchmetrics/segmentation/dice.py index 05a6e29b387..ed151e1b46d 100644 --- a/src/torchmetrics/segmentation/dice.py +++ b/src/torchmetrics/segmentation/dice.py @@ -131,8 +131,7 @@ def update(self, preds: Tensor, target: Tensor) -> None: ) self.numerator.append(numerator) self.denominator.append(denominator) - if self.average == "weighted": - self.support.append(support) + self.support.append(support) def compute(self) -> Tensor: """Computes the Dice Score.""" diff --git a/tests/unittests/segmentation/test_dice.py b/tests/unittests/segmentation/test_dice.py index b009401f481..2828faaf987 100644 --- a/tests/unittests/segmentation/test_dice.py +++ b/tests/unittests/segmentation/test_dice.py @@ -16,6 +16,7 @@ import pytest import torch from sklearn.metrics import f1_score +from torchmetrics import MetricCollection from torchmetrics.functional.segmentation.dice import dice_score from torchmetrics.segmentation.dice import DiceScore @@ -106,3 +107,32 @@ def test_dice_score_functional(self, preds, target, input_format, include_backgr "input_format": input_format, }, ) + + +@pytest.mark.parametrize("compute_groups", [True, False]) +def test_dice_score_metric_collection(compute_groups: bool, num_batches: int = 4): + """Test that the metric works within a metric collection with and without compute groups.""" + metric_collection = MetricCollection( + metrics={ + "DiceScore (micro)": DiceScore( + num_classes=NUM_CLASSES, + average="micro", + ), + "DiceScore (macro)": DiceScore( + num_classes=NUM_CLASSES, + average="macro", + ), + "DiceScore (weighted)": DiceScore( + num_classes=NUM_CLASSES, + average="weighted", + ), + }, + compute_groups=compute_groups, + ) + + for _ in range(num_batches): + metric_collection.update(_inputs1.preds, _inputs1.target) + result = metric_collection.compute() + + assert isinstance(result, dict) + assert len(set(metric_collection.keys()) - set(result.keys())) == 0