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

SCALE + ASH methods #88

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

SCALE + ASH methods #88

wants to merge 20 commits into from

Conversation

paulnovello
Copy link
Member

@paulnovello paulnovello commented Apr 18, 2024

Implements both ASH and SCALE baselines at the same time because they are very similar.

SCALE method

SCALE method basically consists of re-using existing logit-based OOD methods, but with penultimate layer activations scaled. Let $a$ be the activation vector, and $P_p(a)$ the $p$-th percentile of $a$'s values. The scaling is computed using the formula
$s = \exp(\frac{\sum_{i} a_i}{\sum_{a_i > P_p(a)} a_i})$

Here, we focus on a Resnet trained on CIFAR10, challenged on SVHN.

Reference
Scaling for Training Time and Post-hoc Out-of-distribution Detection Enhancement, ICLR 2024
https://arxiv.org/abs/2111.12797

ASH method

This notebook aims at evaluating the ASH method.

ASH method basically consists of re-using existing logit-based OOD methods, but with penultimate layer activations scaled and pruned. Let $a$ be the activation vector, and $P_p(a)$ the $p$-th percentile of $a$'s values. The scaling is computed using the same formula as above. The activation vector is pruned for values $a_i \leq P_p(a)$.

Here, we focus on a Resnet trained on CIFAR10, challenged on SVHN.

Reference
Extremely Simple Activation Shaping for Out-of-Distribution Detection, ICLR 2023
http://arxiv.org/abs/2209.09858

Copy link

github-actions bot commented Apr 23, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
2390 2213 93% 70% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
oodeel/extractor/feature_extractor.py 94% 🟢
oodeel/extractor/keras_feature_extractor.py 97% 🟢
oodeel/extractor/torch_feature_extractor.py 99% 🟢
oodeel/methods/base.py 83% 🟢
oodeel/methods/energy.py 100% 🟢
oodeel/methods/entropy.py 100% 🟢
oodeel/methods/gen.py 96% 🟢
oodeel/methods/mls.py 100% 🟢
oodeel/methods/odin.py 100% 🟢
TOTAL 96% 🟢

updated for commit: 26ee9fb by action🐍

Copy link
Contributor

@cofri cofri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice big PR!

README.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
oodeel/extractor/feature_extractor.py Outdated Show resolved Hide resolved
oodeel/extractor/feature_extractor.py Show resolved Hide resolved
oodeel/extractor/keras_feature_extractor.py Outdated Show resolved Hide resolved
oodeel/extractor/torch_feature_extractor.py Outdated Show resolved Hide resolved
oodeel/extractor/torch_feature_extractor.py Show resolved Hide resolved
)
def test_ash(detector_name, auroc_thr, fpr95_thr):
"""
Test ASH + [MLS, MSP, Energy, ODIN, Entropy] on toy blobs OOD dataset-wise task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you test Entropy and MSP, as suggested in the docstring here? BTW, we could now add GEN.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Entropy and MSP relies on softmax and seems to induce numerical instabilities and Nans. It is the same for GEN. Maybe we should put in the doc that ASH should not be used with Entropy MSP and GEN.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, indeed it can be good to add a warning message somewhere to warn users about ASH

tests/tests_tensorflow/methods/test_tf_ash.py Show resolved Hide resolved
tests/tests_torch/methods/test_torch_ash.py Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants