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

Enable AnomalyScoreMeanVarThreshold based on three-sigma #1052

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

WenjingKangIntel
Copy link
Contributor

@WenjingKangIntel WenjingKangIntel commented Apr 27, 2023

Description

  • Provide a summary of the modification as well as the issue that has been resolved. List any dependencies that this modification necessitates.
  1. Use train data as validation data during validation and collect all the predictions
  2. Based on the predictions above, perform three sigma rule to determine the final threshold: mean - 3 * standard_deviation or mean + 3 * standard_deviation, +/- is determined by config. Currently, only the + scenario should be used, because currently this repo determines the result via checking whether the predictions is larger than the threshold.

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which refactors the code base)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • I have added a summary of my changes to the CHANGELOG (not for minor changes, docs and tests).

@WenjingKangIntel
Copy link
Contributor Author

WenjingKangIntel commented Apr 27, 2023

test on:
model: padim
config:

dataset:
  name: mvtec
  format: mvtec
  path: /home/kangwenj/hackathon/data/mvtec_anomaly_detection
  category: bottle
  task: segmentation
val_split_mode: same_as_train

threshold:
  method: meanvar
  std_dev_ratio: 3
  meanvar_mode: add

result:

Test metric DataLoader 0
image_AUROC 0.9460317492485046
image_F1Score 0.9402984976768494
pixel_AUROC 0.9814534187316895
pixel_F1Score 0.5805442333221436

if using adaptive and val_split_mode: same_as_test:
result:

Test metric DataLoader 0
image_AUROC 0.9936507940292358
image_F1Score 0.9763779044151306
pixel_AUROC 0.983005702495575
pixel_F1Score 0.72203129529953

Actually, when using this meanvar threshold, increasing std_dev_ratio to 10, can get a better result for image_AUROC/image_F1Score:
image_AUROC 0.9936507940292358
image_F1Score 0.9677419662475586
but the pixel_AUROC/pixel_F1Score is not good:
pixel_AUROC 0.7939819097518921
pixel_F1Score 0.3183630406856537

There might be two different sweet spots for image/pixel threshold.

@github-actions github-actions bot added the Tests label Apr 27, 2023
Signed-off-by: Kang Wenjing <[email protected]>
@samet-akcay samet-akcay added the T3 label Apr 28, 2023
Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

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

Thanks. It looks good overall. Just minor comments. Before this can be merged we need to discuss the design for adding more thresholding methods internally.

mean_pred = torch.mean(torch.cat(self.preds, dim=0))
std_pred = torch.std(torch.cat(self.preds, dim=0))
if self.meanvar_mode == MeanVarianceMode.MINUS:
self.value = mean_pred - self.std_dev_ratio * std_pred
Copy link
Collaborator

Choose a reason for hiding this comment

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

As you mentioned in your description this does not make sense in the anomaly context. Maybe we shouldn't support minus operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may add it as a placeholder. If in the future, if we use negative outputs of the model, then minus mode can be used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Enabling Unsupervised Workflow: Propose a new thresholding approach
3 participants