Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics[4 and 5 refactored] save results and compare models [GSoC23 cont'd] #12

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
baff328
normalize axes to ax
jpcbertoldo Aug 18, 2023
d95231c
implement save
jpcbertoldo Aug 18, 2023
af90b25
add and fix tests to save and load
jpcbertoldo Aug 18, 2023
101962e
add demo notebook
jpcbertoldo Aug 18, 2023
a5cf4ff
make auLOGpimo boxplot plot functional
jpcbertoldo Aug 18, 2023
6df11f6
add imgix vs metric or rank plots
jpcbertoldo Aug 21, 2023
19401a1
put models dict validation in common
jpcbertoldo Aug 21, 2023
baf2586
enable higher_is_better=False
jpcbertoldo Aug 21, 2023
c897f89
correct mistake in ranks and make rank plot show draws
jpcbertoldo Aug 21, 2023
20f440c
add pairwise statistical tests
jpcbertoldo Aug 21, 2023
5ab33bc
small changes and comparison of 3 models in nb
jpcbertoldo Aug 21, 2023
26a76e6
add tests and fix small issues
jpcbertoldo Aug 22, 2023
eb0f421
[0] fpr plot bounds colors
jpcbertoldo Aug 22, 2023
48d0085
complete some missing text in notebook
jpcbertoldo Aug 22, 2023
621f58e
complete some module docstrings
jpcbertoldo Aug 22, 2023
837fa7a
make saturation colors and transparent superimposed colormap
jpcbertoldo Aug 24, 2023
ee2cf55
Revert "make saturation colors and transparent superimposed colormap"
jpcbertoldo Aug 25, 2023
c444bbe
write exception messages
jpcbertoldo Aug 25, 2023
9617076
make saturation colors configurable
jpcbertoldo Aug 25, 2023
f018d7c
add tests and fix small issues
jpcbertoldo Aug 25, 2023
2b2c96e
Merge branch 'metrics/next04-compare-models' into metrics/next05-viz
jpcbertoldo Aug 25, 2023
f120e7a
refactor save/load and comparisions
jpcbertoldo Sep 5, 2023
31d869f
fix tests
jpcbertoldo Sep 5, 2023
104d53b
fix notebook kernelspec
jpcbertoldo Sep 5, 2023
33eef64
small fixes
jpcbertoldo Sep 5, 2023
7e1cd36
roll back viz stuff (next pr)
jpcbertoldo Sep 5, 2023
7e696b6
fix types in boxplot
jpcbertoldo Sep 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

855 changes: 855 additions & 0 deletions notebooks/500_use_cases/502_perimg_metrics/502b_compare_models.ipynb

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions src/anomalib/utils/metrics/perimg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
"""Per-Image Metrics.

Overall approach:
Thresholds are computed across all images, but the metrics are computed per-image.
Metrics here are based on binary classification metrics (e.g. FPR, TPR, Precision) over a range of thresholds.

Thresholds are applied across all images, but each image is measured independently.
In other words, thresholds are shared, but metrics are *per-image*.

Thresholds are then indexed by a metric \\in [0, 1] so that any (model, dataset) can be compared.
Key insight: the indexing metric is **only measured on normal images** in the test set.

`PImO`: the shared metric is the mean of per-image FPR (`shared_fpr`).

The indexing metric is then used as the X-axis of curve, where the Y-axis is the per-image metric.

`PImO`: the Y-axis is the per-image TPR, or "Overlap" [between the predicted and ground-truth masks
Therefore `PImO` stands for "Per-Image Overlap [curve]".

Note: by definition, it is only defined on anomalous images.

Finally, the area under each curve is computed.

`PImO` --> `AUPImO` (Area Under the PImO curve).

The shared metric is also used to restrict the threshold range.

`PImO`: one can limit the upper bound (maximum value) of the shared FPR, which is the lower bound of thresholds.

In such cases, the area under the curve is computed over the restricted range and normalized to [0, 1].
Note: that this corresponds to taking the average value of the Y-axis over the restricted range.


Metrics here are generaly based on binary classification metrics (e.g. FPR, TPR, Precision) over a range of thresholds.

Several plot functions are provided to visualize these metrics.

Utilities are also provided to measure statistics over the per-image metric values, especially using boxplots.
"""

from .binclf_curve import PerImageBinClfCurve
Expand Down
13 changes: 4 additions & 9 deletions src/anomalib/utils/metrics/perimg/binclf_curve.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
"""Per-Image Binary Classification Curve.
"""Per-Image Binary Classification (BinClf) Curve.

Binary classification (threshold-dependent) matrix with shared thresholds but per-image counts/rates.
This is a generalization of the binary classification matrix (TP, FP, FN, TN) to a range of thresholds.

Known issue:
At each threshold (shared by all images), the binary classification matrix is computed for each image independently.

Computing the binary classification matrix curve depends on knowing the min and max anomaly scores across all images,
and the current approach is to just stock all anomaly maps and masks in memory and compute the min and max at the end;
a better approach would be to do the computation in two phases/epochs:
1. compute the min and max anomaly scores across all images (no need to stock the anomaly maps and masks)
2. do the actual computation of the binary classification matrix curve, which can actually be done in batches
once the thresholds are known
This module is used as a building block for other modules like `pimo`.
"""

from __future__ import annotations
Expand Down
Loading
Loading