Efficient per-region overlap (PRO) calculation implemented using torchmetrics.
Project description
pyaupro: Efficient Per-Region Overlap Computation
This package is intended to compute the per-region overlap metric using an efficient torchmetrics implementation.
If you are used to torchmetrics, for example to BinaryROC, you will find
yourself at home using pyaupro.
We export a single metric called PerRegionOverlap, which is described in the paper
referenced below.
Bergmann, Paul, Kilian Batzner, Michael Fauser, David Sattlegger, and Carsten Steger. “The MVTec Anomaly Detection Dataset: A Comprehensive Real-World Dataset for Unsupervised Anomaly Detection.” International Journal of Computer Vision 129, no. 4 (April 1, 2021): 1038–59. https://doi.org/10.1007/s11263-020-01400-4.
The arguments to instantiate the metric are as follows.
thresholds:
Can be one of:
- If set to `None`, will use a non-binned reference approach provided by the authors of MVTecAD, where
no thresholds are explicitly calculated. Most accurate but also most memory consuming approach.
- If set to an `int` (larger than 1), will use that number of thresholds linearly spaced from
0 to 1 as bins for the calculation.
- If set to an `list` of floats, will use the indicated thresholds in the list as bins for the calculation
- If set to an 1d `tensor` of floats, will use the indicated thresholds in the tensor as
bins for the calculation.
ignore_index:
Specifies a target value that is ignored and does not contribute to the metric calculation
validate_args: bool indicating if input arguments and tensors should be validated for correctness.
Set to ``False`` for faster computations.
kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
An update of the metric expects a three dimensional preds tensor where the first dimension is the batch dimension (floats between zero and one, otherwise the values are considered logits) equally shaped target tensor containing ground truth labels, and therefore only contain {0,1} values.
If thresholds is None, the metric computes an exact Per-Region Overlap (PRO) curve over all possible values. In this case, each update step appends the given tensors and the calculation happens at compute. We use the official implementation provided in MVTecAD as a reference.
If thresholds are given, the computation is approximate and happens at each update step. In the approximate case, compute returns a mean of the batched computations during update.
We further provide an auc_compute utility for area under the curve computation, which is also used
in PerRegionOverlap if score=True. The arguments for auc_compute are as follows.
x:
Ascending (or descending if ``descending=True``) sorted vector if,
otherwise ``reorder`` must be used.
y:
Vector of the same size as ``x``.
limit:
Integration limit chosen for ``x`` such that only the values until
the limit are used for computation.
descending:
Input vector ``x`` is descending or ``reorder`` sorts descending.
check:
Check if the given vector is monotonically increasing or decreasing.
return_curve:
Return the final tensors used to compute the area under the curve.
How to develop
- Use
uv syncto install dependencies from the lock file. - Use
uv lockto update the lock file given the pinned dependencies. - Use
uv lock --upgradeto upgrade the lock file ignoring pinned dependencies. - Use
uv pip install --editable .to install the local package. - Use
uv run pytest teststo test the local package.
It might happen that the host github.com is not trusted, in this case use uv sync --allow-insecure-host https://github.com if you trust github.com.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyaupro-0.1.0.tar.gz.
File metadata
- Download URL: pyaupro-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa140e0c47ff1790dca177db9ba850bf37fe587e6dd1fc00b2b7b918d7093814
|
|
| MD5 |
6a703f26769dfa8e9ba1779249d5379d
|
|
| BLAKE2b-256 |
255632d25f69669c693ea831ca99252e6ed8d4727208b0bdab66c711b7d4dd34
|
File details
Details for the file pyaupro-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyaupro-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e93e0dce063462e279fc01183b731ba1bdc4741de2c171cfec1c7a020f7ac730
|
|
| MD5 |
5c80242b798d7b9fc5ef95ef76b20dc8
|
|
| BLAKE2b-256 |
734222c23e4c87d41c3609455c1595a4a093a837ae75308a118c6c1084ff804b
|