openvinotoolkit / anomalib

An anomaly detection library comprising state-of-the-art algorithms and features such as experiment management, hyper-parameter optimization, and edge inference.
https://anomalib.readthedocs.io/en/latest/
Apache License 2.0
3.68k stars 653 forks source link

Fastflow lightning CLI method config: No action for destination key OR 'Namespace' object has no attribute 'category' #484

Closed ghost closed 2 years ago

ghost commented 2 years ago

Describe the bug

I use a custom dataset to train Fastflow with the new Lightning CLI Method. If I define 'category' in the config there is an Error:

anomalib: error: Parser key "data": Problem with given class_path "anomalib.data.Folder":
 - 'Configuration check failed :: No action for destination key "category" to check its value.'

When I comment 'category' out in the config, there is an other AttributeError:

File "/home/USERNAME/masterthesis/anomalib/anomalib/utils/cli/cli.py", line 142, in __set_default_root_dir
    category = config.data.init_args.category if config.data.init_args.keys() else ""
AttributeError: 'Namespace' object has no attribute 'category'

To Reproduce

Steps to reproduce the behavior:

model: class_path: anomalib.models.Fastflow init_args: input_size: [256, 256] backbone: wide_resnet50_2 # options: [resnet18, wide_resnet50_2, cait_m48_448, deit_base_distilled_patch16_384] pre_trained: true flow_steps: 8 # options: [8, 8, 20, 20] - for each supported backbone conv3x3_only: False # options: [True, False, False, False] - for each supported backbone hidden_ratio: 1.0 # options: [1.0, 1.0, 0.16, 0.16] - for each supported backbone

...

- Call `anomalib fit --config anomalib_model_config/fastflow_lightning.yaml`
Output is:

anomalib: error: Parser key "data": Problem with given class_path "anomalib.data.Folder":

Expected behavior

Hardware and Software Configuration

samet-akcay commented 2 years ago

Thanks for reporting this @dominikgraf. New LightningCLI is still beta, and we expect this sort of issues. We'll try to fix it asap

ghost commented 2 years ago

Hey again, the bug is still present in the current version, so I took a second look.

The training works after I made a small change to anomalib/anomalib/utils/cli/cli.py and my config. I removed 'category' from the config and removed the keys check in line 146 in cli.py:

Changed from: 146 category = config.data.init_args.category if config.data.init_args.keys() else "" to: 146 category = ""

samet-akcay commented 2 years ago

@dominikgraf, you are right. The error is because category is specified in your config. The new CLI is much stricter when it comes to passing the argument. If they are not part of the class args, it immediately throws error.

In this case, category is not one of the class arguments of the FolderDataset, which is why you encountered this issue.

You don't even need to change the code. If you remove category from your config file, it should work.

ghost commented 2 years ago

Thanks for your answer, @samet-akcay . I tried removing / commenting out 'category' as described in the lower part of my report: