How to do CLASSIFICATION task with config file in 2.0.0 #2777
-
How to do classification task with config file in 2.0.0b3? My custom config yaml file:
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Hello, I have the same issue, don't know how to start with 2.0 - |
Beta Was this translation helpful? Give feedback.
-
Hi, same issue here, I would like to train a classification model without masks. any updates? |
Beta Was this translation helpful? Give feedback.
-
Hi, you can just omit the |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
With Anomalib v2, task is handled under the hood, so you don't need to specify anything. Depending on what you pass as input data, Anomalib ensures whether it is a classification or segmentation task. If you want to customise, things we split everything into the following categories:
So, each model now has the corresponding In your case, you don't pass ground truth masks, so you might want some customised metric evaluation and visualisation. Let's have a look how you could do it. Custom Evaluationvia APIfrom anomalib.data import Folder
from anomalib.engine import Engine
from anomalib.metrics import Evaluator, F1Score
from anomalib.models import Patchcore
datamodule = Folder(
name="hazelnut",
normal_dir="train/good",
root="datasets/MVTec/hazelnut",
abnormal_dir=["test/crack", "test/cut", "test/hole", "test/print"],
normal_test_dir="test/good",
)
evaluator = Evaluator(
test_metrics=[
F1Score(fields=["pred_score", "gt_label"]),
],
)
model = Patchcore(
backbone="wide_resnet50_2",
layers=["layer2", "layer3"],
pre_trained=True,
coreset_sampling_ratio=0.1,
num_neighbors=9,
evaluator=evaluator,
)
engine = Engine()
engine.train(model=model, datamodule=datamodule) via CLIYou just need to pass the evaluator configuration to model:
class_path: anomalib.models.Patchcore
init_args:
backbone: wide_resnet50_2
layers:
- layer2
- layer3
pre_trained: true
coreset_sampling_ratio: 0.1
num_neighbors: 9
pre_processor: true
post_processor: true
evaluator:
class_path: anomalib.metrics.Evaluator
init_args:
test_metrics:
- class_path: anomalib.metrics.F1Score
init_args:
fields: ["pred_score", "gt_label"] Custom EvaluationAnomalib handles the visualization for you, using the available fields in your dataset. In case you want some customization, here is how you could do that. via APIfrom anomalib.visualization import ImageVisualizer
visualizer = ImageVisualizer(
fields=["image", "anomaly_map"],
overlay_fields=[("image", ["anomaly_map"]), ("image", ["pred_mask"])],
)
model.visualizer = visualizer
# The rest is the same.. via CLIYou can add the custom visualizer config to the model config: model:
class_path: anomalib.models.Patchcore
init_args:
backbone: wide_resnet50_2
layers:
- layer2
- layer3
pre_trained: true
coreset_sampling_ratio: 0.1
num_neighbors: 9
pre_processor: true
post_processor: true
evaluator:
class_path: anomalib.metrics.Evaluator
init_args:
test_metrics:
- class_path: anomalib.metrics.F1Score
init_args:
fields: ["pred_score", "gt_label"]
visualizer:
class_path: anomalib.visualization.ImageVisualizer
init_args:
fields: ["image", "anomaly_map"]
overlay_fields:
- - image
- [anomaly_map]
- - image
- [pred_mask] |
Beta Was this translation helpful? Give feedback.
-
Let me know if there are other parts you need clarification. Thanks! |
Beta Was this translation helpful? Give feedback.
With Anomalib v2, task is handled under the hood, so you don't need to specify anything. Depending on what you pass as input data, Anomalib ensures whether it is a classification or segmentation task.
If you want to customise, things we split everything into the following categories:
So, each model now has the corresponding
pre_processor
,model
,post_processor
,evaluator
andvisualizer
modules. If you want to customise them you can do via both CLI and API.In your case, you don't pass ground truth masks, so you might want some customised metric evaluation and visualisation. Let's have a look how you could do it.
C…