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

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

Closed
ghost opened this issue Aug 4, 2022 · 4 comments · Fixed by #567
Assignees
Labels
Bug Something isn't working CLI

Comments

@ghost
Copy link

ghost commented Aug 4, 2022

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:

  • Create config for Fastflow with custom Dataset:
# This is the config file for the new Anomalib CLI.
# To use this, run the following command:
# anomalib fit --config ./config/model/fastflow.yaml
ckpt_path: null
seed_everything: null
data:
  class_path: anomalib.data.Folder
  init_args:
    root: ./synthetic_data/anomalib_lego_dataset
    category: lego # not used in anomalib.data.Folder
    normal_dir: good
    abnormal_dir: abnormal
    task: segmentation
    mask_dir: ./synthetic_data/anomalib_lego_dataset/mask
    extensions: ['.jpg']
    normal_test_dir: null
    split_ratio: 0.2
    seed: 0
    image_size: [256,256] # options: [256, 256, 448, 384] - for each supported backbone
    train_batch_size: 16
    test_batch_size: 16
    num_workers: 8
    transform_config_train: null
    transform_config_val: null
    create_validation_set: true
    #tiling:
      #apply: false
      #tile_size: null
      #stride: null
      #remove_border_count: 0
      #use_random_tiling: False
      #random_tile_count: 16

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":
 - 'Configuration check failed :: No action for destination key "category" to check its value.'
  • Modify Config File by commenting 'category' out and call anomalib fit --config anomalib_model_config/fastflow_lightning.yaml
    Output is:
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'

Expected behavior

  • Training should work by leaving out 'category'

Hardware and Software Configuration

  • OS: [Ubuntu 20.04]
  • NVIDIA Driver Version [515.65.01]
  • CUDA Version [11.7]
  • CUDNN Version [V10.1.243]
@samet-akcay
Copy link
Contributor

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

@samet-akcay samet-akcay added Bug Something isn't working CLI labels Aug 4, 2022
@ghost
Copy link
Author

ghost commented Aug 29, 2022

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 samet-akcay self-assigned this Sep 9, 2022
@samet-akcay
Copy link
Contributor

@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
Copy link
Author

ghost commented Sep 19, 2022

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

  • Modify config file by removing / commenting out 'category' and call anomalib fit --config anomalib_model_config/fastflow_lightning.yaml again
    Output is:
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 me it seems that, the check of 'keys()' is skipped for some reason.
Removing 'category' from my config did not solve the Error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant