Skip to content

Commit

Permalink
Merge branch 'master' into curve_average
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda authored Oct 3, 2023
2 parents 9a86e05 + 2387f2a commit 966c91a
Show file tree
Hide file tree
Showing 32 changed files with 154 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def set_min_torch_by_python(fpath: str = "requirements/base.txt") -> None:
return
with open(fpath) as fp:
reqs = parse_requirements(fp.readlines())
pkg_ver = [p for p in reqs if p.name == "torch"][0]
pkg_ver = next(p for p in reqs if p.name == "torch")
pt_ver = min([LooseVersion(v[1]) for v in pkg_ver.specs])
pt_ver = max(LooseVersion(LUT_PYTHON_TORCH[py_ver]), pt_ver)
with open(fpath) as fp:
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@ repos:
- id: detect-private-key

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.14.0
hooks:
- id: pyupgrade
args: [--py38-plus]
args: ["--py38-plus"]
name: Upgrade code

- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: [tomli]
#args: ["--write-changes"]
args: ["--write-changes"]
exclude: pyproject.toml

- repo: https://github.com/crate-ci/typos
rev: v1.16.12
rev: v1.16.17
hooks:
- id: typos
# empty to do not write fixes
Expand All @@ -68,13 +68,13 @@ repos:
args: ["--in-place"]

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
name: Format code

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
Expand Down Expand Up @@ -130,7 +130,7 @@ repos:
- id: text-unicode-replacement-char

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.277
rev: v0.0.292
hooks:
- id: ruff
args: ["--fix"]
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ addopts = [
#filterwarnings = ["error::FutureWarning"] # ToDo
xfail_strict = true
junit_duration_report = "call"

[tool.coverage.report]
exclude_lines = ["pragma: no cover", "pass"]

[tool.coverage.run]
parallel = true
concurrency = "thread"
Expand Down Expand Up @@ -81,6 +79,7 @@ wil = "wil"


[tool.ruff]
target-version = "py38"
line-length = 120
# Enable Pyflakes `E` and `F` codes by default.
select = [
Expand Down Expand Up @@ -122,6 +121,8 @@ ignore = [
"S301", # todo: `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue # todo
"S310", # todo: Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected. # todo
"B905", # todo: `zip()` without an explicit `strict=` parameter
"PYI024", # todo: Use `typing.NamedTuple` instead of `collections.namedtuple`
"PYI041", # todo: Use `float` instead of `int | float``
]
# Exclude a variety of commonly ignored directories.
exclude = [
Expand Down
4 changes: 2 additions & 2 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 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

coverage ==7.3.1
coverage ==7.3.2
pytest ==7.4.2
pytest-cov ==4.1.0
pytest-doctestplus ==1.0.0
Expand All @@ -14,4 +14,4 @@ requests <=2.31.0
fire <=0.5.0

cloudpickle >1.3, <=2.2.1
scikit-learn >=1.1.1, <1.3.1
scikit-learn >=1.1.1, <1.4.0
12 changes: 6 additions & 6 deletions src/torchmetrics/audio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@
]

if _PESQ_AVAILABLE:
from torchmetrics.audio.pesq import PerceptualEvaluationSpeechQuality # noqa: F401
from torchmetrics.audio.pesq import PerceptualEvaluationSpeechQuality

__all__.append("PerceptualEvaluationSpeechQuality")
__all__ += ["PerceptualEvaluationSpeechQuality"]

if _PYSTOI_AVAILABLE:
from torchmetrics.audio.stoi import ShortTimeObjectiveIntelligibility # noqa: F401
from torchmetrics.audio.stoi import ShortTimeObjectiveIntelligibility

__all__.append("ShortTimeObjectiveIntelligibility")
__all__ += ["ShortTimeObjectiveIntelligibility"]

if _GAMMATONE_AVAILABLE and _TORCHAUDIO_AVAILABLE and _TORCHAUDIO_GREATER_EQUAL_0_10:
from torchmetrics.audio.srmr import SpeechReverberationModulationEnergyRatio # noqa: F401
from torchmetrics.audio.srmr import SpeechReverberationModulationEnergyRatio

__all__.append("SpeechReverberationModulationEnergyRatio")
__all__ += ["SpeechReverberationModulationEnergyRatio"]
2 changes: 1 addition & 1 deletion src/torchmetrics/audio/stoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ShortTimeObjectiveIntelligibility(Metric):
The STOI-measure is intrusive, i.e., a function of the clean and degraded speech signals. STOI may be a good
alternative to the speech intelligibility index (SII) or the speech transmission index (STI), when you are
interested in the effect of nonlinear processing to noisy speech, e.g., noise reduction, binary masking algorithms,
on speech intelligibility. Description taken from `Cees Taal's website`_ and for further defails see `STOI ref1`_
on speech intelligibility. Description taken from `Cees Taal's website`_ and for further details see `STOI ref1`_
and `STOI ref2`_.
This metric is a wrapper for the `pystoi package`_. As the implementation backend implementation only supports
Expand Down
9 changes: 8 additions & 1 deletion src/torchmetrics/classification/accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class BinaryAccuracy(BinaryStatScores):
If ``multidim_average`` is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of a scalar
value per sample.
Additional dimension ``...`` will be flattened into the batch dimension.
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
threshold: Threshold for transforming probability to binary {0,1} predictions
Expand Down Expand Up @@ -176,6 +177,9 @@ class MulticlassAccuracy(MulticlassStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_classes: Integer specifying the number of classes
average:
Expand Down Expand Up @@ -325,6 +329,9 @@ class MultilabelAccuracy(MultilabelStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_labels: Integer specifying the number of labels
threshold: Threshold for transforming probability to binary (0,1) predictions
Expand Down
8 changes: 6 additions & 2 deletions src/torchmetrics/classification/exact_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ class MulticlassExactMatch(Metric):
probabilities/logits into an int tensor.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, ...)``.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``mcem`` (:class:`~torch.Tensor`): A tensor whose returned shape depends on the ``multidim_average`` argument:
- If ``multidim_average`` is set to ``global`` the output will be a scalar tensor
- If ``multidim_average`` is set to ``samplewise`` the output will be a tensor of shape ``(N,)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_classes: Integer specifying the number of labels
multidim_average:
Expand Down Expand Up @@ -206,14 +208,16 @@ class MultilabelExactMatch(Metric):
sigmoid per element. Additionally, we convert to int tensor with thresholding using the value in ``threshold``.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, C, ...)``.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``mlem`` (:class:`~torch.Tensor`): A tensor whose returned shape depends on the ``multidim_average`` argument:
- If ``multidim_average`` is set to ``global`` the output will be a scalar tensor
- If ``multidim_average`` is set to ``samplewise`` the output will be a tensor of shape ``(N,)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_labels: Integer specifying the number of labels
threshold: Threshold for transforming probability to binary (0,1) predictions
Expand Down
20 changes: 18 additions & 2 deletions src/torchmetrics/classification/f_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class BinaryFBetaScore(BinaryStatScores):
- If ``multidim_average`` is set to ``samplewise`` the output will be a tensor of shape ``(N,)`` consisting of
a scalar value per sample.
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
beta: Weighting between precision and recall in calculation. Setting to 1 corresponds to equal weight
threshold: Threshold for transforming probability to binary {0,1} predictions
Expand Down Expand Up @@ -202,7 +205,6 @@ class MulticlassFBetaScore(MulticlassStatScores):
probabilities/logits into an int tensor.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, ...)``.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``mcfbs`` (:class:`~torch.Tensor`): A tensor whose returned shape depends on the ``average`` and
Expand All @@ -218,6 +220,9 @@ class MulticlassFBetaScore(MulticlassStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
beta: Weighting between precision and recall in calculation. Setting to 1 corresponds to equal weight
num_classes: Integer specifying the number of classes
Expand Down Expand Up @@ -382,7 +387,6 @@ class MultilabelFBetaScore(MultilabelStatScores):
per element. Additionally, we convert to int tensor with thresholding using the value in ``threshold``.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, C, ...)``.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``mlfbs`` (:class:`~torch.Tensor`): A tensor whose returned shape depends on the ``average`` and
Expand All @@ -398,6 +402,9 @@ class MultilabelFBetaScore(MultilabelStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
beta: Weighting between precision and recall in calculation. Setting to 1 corresponds to equal weight
num_labels: Integer specifying the number of labels
Expand Down Expand Up @@ -566,6 +573,9 @@ class BinaryF1Score(BinaryFBetaScore):
- If ``multidim_average`` is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of a scalar
value per sample.
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
threshold: Threshold for transforming probability to binary {0,1} predictions
multidim_average:
Expand Down Expand Up @@ -706,6 +716,9 @@ class MulticlassF1Score(MulticlassFBetaScore):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
preds: Tensor with predictions
target: Tensor with true labels
Expand Down Expand Up @@ -876,6 +889,9 @@ class MultilabelF1Score(MultilabelFBetaScore):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)```
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_labels: Integer specifying the number of labels
threshold: Threshold for transforming probability to binary (0,1) predictions
Expand Down
11 changes: 9 additions & 2 deletions src/torchmetrics/classification/hamming.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class BinaryHammingDistance(BinaryStatScores):
- If ``multidim_average`` is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of a
scalar value per sample.
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
threshold: Threshold for transforming probability to binary {0,1} predictions
multidim_average:
Expand Down Expand Up @@ -171,7 +174,6 @@ class MulticlassHammingDistance(MulticlassStatScores):
probabilities/logits into an int tensor.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, ...)``.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``mchd`` (:class:`~torch.Tensor`): A tensor whose returned shape depends on the ``average`` and
Expand All @@ -187,6 +189,9 @@ class MulticlassHammingDistance(MulticlassStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_classes: Integer specifying the number of classes
average:
Expand Down Expand Up @@ -324,7 +329,6 @@ class MultilabelHammingDistance(MultilabelStatScores):
``threshold``.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, C, ...)``.
As output to ``forward`` and ``compute`` the metric returns the following output:
- ``mlhd`` (:class:`~torch.Tensor`): A tensor whose returned shape depends on the ``average`` and
Expand All @@ -340,6 +344,9 @@ class MultilabelHammingDistance(MultilabelStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_labels: Integer specifying the number of labels
threshold: Threshold for transforming probability to binary (0,1) predictions
Expand Down
18 changes: 18 additions & 0 deletions src/torchmetrics/classification/precision_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class BinaryPrecision(BinaryStatScores):
value. If ``multidim_average`` is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of a
scalar value per sample.
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
threshold: Threshold for transforming probability to binary {0,1} predictions
multidim_average:
Expand Down Expand Up @@ -187,6 +190,9 @@ class MulticlassPrecision(MulticlassStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_classes: Integer specifying the number of classes
average:
Expand Down Expand Up @@ -340,6 +346,9 @@ class MultilabelPrecision(MultilabelStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_labels: Integer specifying the number of labels
threshold: Threshold for transforming probability to binary (0,1) predictions
Expand Down Expand Up @@ -479,6 +488,9 @@ class BinaryRecall(BinaryStatScores):
value. If ``multidim_average`` is set to ``samplewise``, the metric returns ``(N,)`` vector consisting of
a scalar value per sample.
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
threshold: Threshold for transforming probability to binary {0,1} predictions
multidim_average:
Expand Down Expand Up @@ -608,6 +620,9 @@ class MulticlassRecall(MulticlassStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_classes: Integer specifying the number of classes
average:
Expand Down Expand Up @@ -760,6 +775,9 @@ class MultilabelRecall(MultilabelStatScores):
- If ``average='micro'/'macro'/'weighted'``, the shape will be ``(N,)``
- If ``average=None/'none'``, the shape will be ``(N, C)``
If ``multidim_average`` is set to ``samplewise`` we expect at least one additional dimension ``...`` to be present,
which the reduction will then be applied over instead of the sample dimension ``N``.
Args:
num_labels: Integer specifying the number of labels
threshold: Threshold for transforming probability to binary (0,1) predictions
Expand Down
Loading

0 comments on commit 966c91a

Please sign in to comment.