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

[Bug]: Strict flag not passed when Metrics istantiend #2541

Open
1 task done
LorenzoF6 opened this issue Jan 29, 2025 · 6 comments
Open
1 task done

[Bug]: Strict flag not passed when Metrics istantiend #2541

LorenzoF6 opened this issue Jan 29, 2025 · 6 comments

Comments

@LorenzoF6
Copy link

Describe the bug

If i want to train patchore for a classification task, i see that in v2 folder does not accept as input parameter task="classification". So i trying using the strict parameter (set to false to evaluator's pixel metrics) but it say that

"Unexpected keyword arguments: strict "

for adding the strict = False to the pixel metrics and if i remove this it worked but during the train i recevie another bug :

"NoneType' object has no attribute 'flatten' that indicates that i'm trying to call the flatten method on a variable that is currently None. The problem arises i think in the BinaryPrecisionRecallCurve._binary_precision_recall_curve_format function within the post-processing step of Anomalib, where it expects the target (ground truth mask) to be a valid tensor. However, it seems that for some of my validation data in datamodule_DISCHITOP, the ground truth mask is missing or not properly loaded, resulting in target being None"

Dataset

Folder

Model

PatchCore

Steps to reproduce the behavior

IMPORT

from anomalib.data import Folder
from anomalib.models import Patchcore
from anomalib.models import Padim
from anomalib.engine import Engine
from anomalib.metrics import F1Score, AUROC
from anomalib.metrics import Evaluator
from anomalib.post_processing import OneClassPostProcessor

DATA PREPARATION

datamodule_DISCHITOP = Folder(
name = "DISCHITOP",
root = Dataset_path_DISCHITOP ,
normal_dir = "train/good",
abnormal_dir = "test/defective",
normal_test_dir = "test/good",
)
datamodule_DISCHITOP.setup()

SETUP

engine = Engine()
test_metrics = [
AUROC(fields=["pred_score", "gt_label"], prefix="image_"), # Image-level AUROC
F1Score(fields=["pred_label", "gt_label"], prefix="image_"), # Image-level F1
AUROC(fields=["anomaly_map", "gt_mask"], prefix = "pixel_", strict = False), # Pixel-level AUROC
F1Score(fields=["pred_mask", "gt_mask"], prefix = "pixel_", strict = False) # Pixel-level F1

]
evaluator_DISCHITOP = Evaluator(test_metrics = test_metrics)
model_patchcore_DISCHITOP = Patchcore(evaluator = evaluator)

TRAIN

engine.fit(model = model_patchcore_DISCHITOP, datamodule = datamodule_DISCHITOP)

OS information

OS information:

  • OS: [e.g. Ubuntu 20.04]
  • Python version: [e.g. 3.10.0]
  • Anomalib version: [e.g. 0.3.6]
  • PyTorch version: [e.g. 1.9.0]
  • CUDA/cuDNN version: [e.g. 11.1]
  • GPU models and configuration: [e.g. 2x GeForce RTX 3090]
  • Any other relevant information: [e.g. I'm using a custom dataset]

Expected behavior

The model trained for classification

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

No response

Configuration YAML

N/A

Logs

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct
@LorenzoF6
Copy link
Author

EDIT: in my case i try to see the base.py file for metrcis in the anomalib installaion but the strict parameter it is not present in that file
I installed it by !pip install anomalib[full]==2.0.0b2 on Google Colab
May i try to clone the repository directyl by github and then installed it ?

@alexriedel1
Copy link
Contributor

EDIT: in my case i try to see the base.py file for metrcis in the anomalib installaion but the strict parameter it is not present in that file I installed it by !pip install anomalib[full]==2.0.0b2 on Google Colab May i try to clone the repository directyl by github and then installed it ?

Yes I think the feature is not yet present in the pypy build available via pip. You have to go via development install: https://github.com/openvinotoolkit/anomalib?tab=readme-ov-file#-development-install

@LorenzoF6
Copy link
Author

yes infact installing it by cloning the repository and using !pip install -e .[full] the strict parameter was added
if i want to update the library by not cloning one more time the repo on github and reinstalling there is any command that i can use?
Thanks a lot

@alexriedel1
Copy link
Contributor

yes infact installing it by cloning the repository and using !pip install -e .[full] the strict parameter was added if i want to update the library by not cloning one more time the repo on github and reinstalling there is any command that i can use? Thanks a lot

You could try to pip install --upgrade git+git://github.com/openvinotoolkit/anomalib but I wouldn't do that and just deinstall and reinstall from the git repo

@LorenzoF6
Copy link
Author

ok unnderstood, thanks.
For deinstall it is correct to go (using cd) to the anomalib folder and use the command !pip uninstall anomalib -y ?

@alexriedel1
Copy link
Contributor

ok unnderstood, thanks. For deinstall it is correct to go (using cd) to the anomalib folder and use the command !pip uninstall anomalib -y ?

If you installed it via !pip install anomalib[full]==2.0.0b2 you don't have to navigate to any specific folder for uninstalling.
Also you are saying that you are on Colab, just reset your session and everything will be deleted anyways :)

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

No branches or pull requests

2 participants