❓ <title>Guidance on Multi-Category Training for Dinomaly Model #2926
Unanswered
luminous33
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Thanks for submitting this issue! It has been added to our triage queue. A maintainer will review it shortly. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @luminous33 Currently Dinomaly model in Anomalib supports only single-class anomaly detection. Adding multi-class support is planned but no one is actively working on it at the moment. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Your Question
Hello Anomalib Team,
I am trying to train the Dinomaly model on multiple categories of the Visa dataset simultaneously (e.g., pcb1, pcb2, pcb3, and pcb4) in a single training run.
Based on the discussion in issue #2782, it seems that training on multiple categories is a supported feature. However, I have encountered errors with both the CLI (config.yaml) and a direct Python script approach. I would appreciate some guidance on the correct procedure.
Here is what I have tried so far:
I tried to run the training using a config.yaml file that specifies a list of categories.
Command:
Bash
anomalib train --config sample.yaml
sample.yaml content:
YAML
data:
class_path: anomalib.data.Visa
init_args:
root: /data/data/visa/visa_dataset/
category:
- pcb1
- pcb2
- pcb3
- pcb4
model:
class_path: anomalib.models.Dinomaly
Error:
This approach fails with a parser error, indicating that the category key expects a string, not a list.
error: Parser key "data":
Does not validate against any of the Union subtypes
Subtypes: [<class 'NoneType'>, <class 'anomalib.data.datamodules.base.image.AnomalibDataModule'>]
Errors:
- Expected a <class 'NoneType'>
- Problem with given class_path 'anomalib.data.Visa':
Parser key "category":
Expected a <class 'str'>. Got value: ['pcb1', 'pcb2', 'pcb3', 'pcb4']
Given value type: <class 'dict'>
Given value: {'class_path': 'anomalib.data.Visa', 'init_args': {'root': '/data/data/visa/visa_pytorch/', 'category': ['pcb1', 'pcb2', 'pcb3', 'pcb4']}}
2. Python Script Attempt
Next, I tried using a Python script to instantiate the VisaDataModule with a list of categories.
train.py script:
Python
from anomalib.data import VisaDataModule
from anomalib.models import Dinomaly
from anomalib.engine import Engine
if name == "main":
datamodule = VisaDataModule(
root="/data/data/visa/visa_dataset/",
category=["pcb1", "pcb2", "pcb3", "pcb4"],
image_size=(256, 256),
train_batch_size=32
)
Error:
This script fails with a TypeError when the Engine tries to create a results directory, as it cannot append a list to a Path object.
Traceback (most recent call last):
File "/data/model/anomalib/dino_train_gemini.py", line 38, in
engine.fit(model=model, datamodule=datamodule)
File "/data/model/anomalib/src/anomalib/engine/engine.py", line 404, in fit
self._setup_workspace(
File "/data/model/anomalib/src/anomalib/engine/engine.py", line 297, in _setup_workspace
root_dir = Path(self._cache.args["default_root_dir"]) / model.name / dataset_name / category
TypeError: unsupported operand type(s) for /: 'PosixPath' and 'list'
My Question
Both errors suggest that the category parameter is designed to accept a single string. Could you please clarify the correct way to configure anomalib to train a single model on multiple categories at once, as suggested in issue #2782?
Is there a different configuration key, a specific data module (e.g., a multi-class variant), or a different approach I should be using for this purpose? Or have I misunderstood the scope of the multi-category feature?
Thank you for your time and help!
Environment
Anomalib Version: 2.1.0
torch Version:
torch 2.5.1+cu124
torchaudio 2.5.1+cu124
torchmetrics 1.8.1
torchvision 0.20.1+cu124
Python Version: 3.11
OS: Ubuntu 22.04
Forum Check
Beta Was this translation helpful? Give feedback.
All reactions