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.73k stars 666 forks source link

[Bug]: Transform Config can not be loaded #1770

Closed LeAyky closed 7 months ago

LeAyky commented 8 months ago

Describe the bug

Hey there,

I've just upgraded from v0.7 to the latest version. A lot has changed and I converted my config to accommodate the changes.

Now, when trying to use my transform config (albumentations in .yaml file), I receive the error:

error: Parser key "data":
  Problem with given class_path 'anomalib.data.Folder':
    Parser key "transform_config_train":
      'str' object does not support item assignment

As I am not sure where the error occurs, I'd love your help. Below you can find my configuration file.

I tried upgrading my albumentations package and creating a new transform file but it did not help either.

Maybe I am just overlooking something very obvious, but I cannot find it out myself right now.

Thank you all so much in advance!

Dataset

Other (please specify in the text field below)

Model

Other (please specify in the field below)

Steps to reproduce the behavior

  1. Install anomalib via github
  2. Install dependencies
  3. Create transform yaml via albumentations package
  4. Create custom config with transforms path under transform_config_train
  5. Start training via CLI with the custom config

OS information

OS: Ubuntu 22.04 GPU: RTX 4090 CPU: Ryzen 7 7700

Expected behavior

Start training with transforms like it did with v0.7.

Screenshots

No response

Pip/GitHub

GitHub

What version/branch did you use?

latest

Configuration YAML

yaml
seed_everything: 13371337
model:
  class_path: anomalib.models.Uflow
  init_args:
    flow_steps: 4
    permute_soft: false
    affine_clamp: 2.0
    affine_subnet_channels_ratio: 1.0
    backbone: mcait # official: mcait, other extractors tested: resnet18, wide_resnet50_2. Could use others...

metrics:
  image:
  - F1Score
  - AUROC

# PL Trainer Args. Don't add extra parameter here.
trainer:
  max_epochs: 200
  log_every_n_steps: 9
  callbacks:
    - class_path: lightning.pytorch.callbacks.EarlyStopping
      init_args:
        patience: 20
        monitor: image_AUROC
        mode: max
  logger:
    class_path: lightning.pytorch.loggers.WandbLogger

task: classification
data:
  class_path: anomalib.data.Folder
  init_args:
    normal_dir: train/good
    root: /home/deeplearning/Pictures/uflow/dataset
    abnormal_dir: test/bad
    normal_test_dir: test/good
    mask_dir: null
    normal_split_ratio: 0.0
    extensions: null
    image_size:
    - 448
    - 448
    center_crop: null
    normalization: none
    train_batch_size: 16
    eval_batch_size: 16
    num_workers: 16
    task: classification
    test_split_mode: from_dir
    test_split_ratio: 0.2
    val_split_mode: same_as_test
    val_split_ratio: 0.5
    seed: null
    transform_config_train: /home/deeplearning/projects/anomalib/training/cfg/augmentations/contrast.yaml
    transform_config_eval: /home/deeplearning/projects/anomalib/training/cfg/augmentations/contrast.yaml

results_dir:
  path: results/uflow
  unique: true

Logs


shell
(venv) (base) deeplearning@gym:~/projects/anomalib/training/$ anomalib train --config cfg/uflow.yaml
Usage: anomalib [options] train [-h] [-c CONFIG] [--print_config [=flags]] [--seed_everything SEED_EVERYTHING] [--trainer CONFIG] [--trainer.accelerator.help CLASS_PATH_OR_NAME] [--trainer.accelerator ACCELERATOR] [--trainer.strategy.help CLASS_PATH_OR_NAME]
                                [--trainer.strategy STRATEGY] [--trainer.devices DEVICES] [--trainer.num_nodes NUM_NODES] [--trainer.precision PRECISION] [--trainer.logger.help CLASS_PATH_OR_NAME] [--trainer.logger LOGGER] [--trainer.callbacks.help CLASS_PATH_OR_NAME]
                                [--trainer.callbacks CALLBACKS] [--trainer.fast_dev_run FAST_DEV_RUN] [--trainer.max_epochs MAX_EPOCHS] [--trainer.min_epochs MIN_EPOCHS] [--trainer.max_steps MAX_STEPS] [--trainer.min_steps MIN_STEPS] [--trainer.max_time MAX_TIME]
                                [--trainer.limit_train_batches LIMIT_TRAIN_BATCHES] [--trainer.limit_val_batches LIMIT_VAL_BATCHES] [--trainer.limit_test_batches LIMIT_TEST_BATCHES] [--trainer.limit_predict_batches LIMIT_PREDICT_BATCHES]
                                [--trainer.overfit_batches OVERFIT_BATCHES] [--trainer.val_check_interval VAL_CHECK_INTERVAL] [--trainer.check_val_every_n_epoch CHECK_VAL_EVERY_N_EPOCH] [--trainer.num_sanity_val_steps NUM_SANITY_VAL_STEPS]
                                [--trainer.log_every_n_steps LOG_EVERY_N_STEPS] [--trainer.enable_checkpointing {true,false,null}] [--trainer.enable_progress_bar {true,false,null}] [--trainer.enable_model_summary {true,false,null}]
                                [--trainer.accumulate_grad_batches ACCUMULATE_GRAD_BATCHES] [--trainer.gradient_clip_val GRADIENT_CLIP_VAL] [--trainer.gradient_clip_algorithm GRADIENT_CLIP_ALGORITHM] [--trainer.deterministic DETERMINISTIC] [--trainer.benchmark {true,false,null}]
                                [--trainer.inference_mode {true,false}] [--trainer.use_distributed_sampler {true,false}] [--trainer.profiler.help CLASS_PATH_OR_NAME] [--trainer.profiler PROFILER] [--trainer.detect_anomaly {true,false}] [--trainer.barebones {true,false}]
                                [--trainer.plugins.help CLASS_PATH_OR_NAME] [--trainer.plugins PLUGINS] [--trainer.sync_batchnorm {true,false}] [--trainer.reload_dataloaders_every_n_epochs RELOAD_DATALOADERS_EVERY_N_EPOCHS]
                                [results_dir.path --> trainer.default_root_dir [applied on parse]] [--model.help CLASS_PATH_OR_NAME] --model CONFIG | CLASS_PATH_OR_NAME | .INIT_ARG_NAME VALUE [--data.help CLASS_PATH_OR_NAME]
                                [--data CONFIG | CLASS_PATH_OR_NAME | .INIT_ARG_NAME VALUE] [--normalization CONFIG] [--normalization.normalization_method.help CLASS_PATH_OR_NAME] [--normalization.normalization_method NORMALIZATION_METHOD]
                                [--visualization.visualizers.help CLASS_PATH_OR_NAME] [--visualization.visualizers VISUALIZERS] [--visualization.save {true,false}] [--visualization.log {true,false}] [--visualization.show {true,false}] [--task TASK] [--metrics.image IMAGE]
                                [--metrics.pixel PIXEL] [--metrics.threshold.help CLASS_PATH_OR_NAME] [--metrics.threshold THRESHOLD] [--logging.log_graph {true,false}] [--results_dir.path PATH] [--results_dir.unique {true,false}] [--ckpt_path CKPT_PATH]
error: Parser key "data":
  Problem with given class_path 'anomalib.data.Folder':
    Parser key "transform_config_train":
      'str' object does not support item assignment

Code of Conduct

samet-akcay commented 8 months ago

Hi @LeAyky, thanks for reporting this. Have you used this config migration tool? https://github.com/openvinotoolkit/anomalib/blob/main/tools/upgrade/config.py

Not sure if it is related, but would like to see if you still have the issue?

LeAyky commented 8 months ago

Hi @LeAyky, thanks for reporting this. Have you used this config migration tool? https://github.com/openvinotoolkit/anomalib/blob/main/tools/upgrade/config.py

Not sure, if it is related, but would like to see if you still have the issue?

Thank you for your answer!

Yes, I have used that tool. Also tried to use a .json, all kinds of quotations but nothing seems to work.

I am still experiencing this issue.

samet-akcay commented 8 months ago

ok, another possibility is that I'm not sure if the CLI properly parses this augmentation config file. @ashwinvaidya17 any thoughts?

It is also important to note that we plan to switch to torchvision transforms before the official v1 release. Maybe we could also provide a migration guide for this too..

For details, you could refer to this PR https://github.com/openvinotoolkit/anomalib/pull/1706

samet-akcay commented 7 months ago

@LeAyky, now that we merged PR https://github.com/openvinotoolkit/anomalib/pull/1706, can you try this with torchvision please?

LeAyky commented 7 months ago

@LeAyky, now that we merged PR #1706, can you try this with torchvision please?

Thank you @samet-akcay, I am now using the API to access it and with that it works!

Thank you so much for your response and fantastic work.