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.82k stars 679 forks source link

[Bug]: ConfigAttributeError in 001_getting_started.ipynb #891

Closed yjwong1999 closed 1 year ago

yjwong1999 commented 1 year ago

Describe the bug

Hi, Anomalib Teams,

Firstly, thanks a lot for providing this wonderful tools! I'm planning to use it for my current research for long term development.

I'm prototyping using the 001_getting_started.ipynb in Google Colab Open In Colab

However, I encountered "ConfigAttributeError" when I run the following codes: datamodule = get_datamodule(config)

Any idea to solve this? Thanks a lot in advance.

Dataset

MVTec

Model

PADiM

Steps to reproduce the behavior

Steps to reproduce:

  1. Run the 001_getting_started.ipynb
  2. Run all codes until datamodule = get_datamodule(config)

OS information

OS information:

I'm using the default setting in the Colab.

Expected behavior

ConfigAttributeError

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

0.3.7 (the def

Configuration YAML

dataset:
  name: mvtec
  format: mvtec
  path: ./datasets/MVTec
  category: bottle
  task: segmentation
  train_batch_size: 32
  eval_batch_size: 32
  num_workers: 8
  image_size: 256 # dimensions to which images are resized (mandatory)
  center_crop: null # dimensions to which images are center-cropped after resizing (optional)
  normalization: imagenet # data distribution to which the images will be normalized: [none, imagenet]
  transform_config:
    train: null
    eval: null
  test_split_mode: from_dir # options: [from_dir, synthetic]
  test_split_ratio: 0.2 # fraction of train images held out testing (usage depends on test_split_mode)
  val_split_mode: same_as_test # options: [same_as_test, from_test, synthetic]
  val_split_ratio: 0.5 # fraction of train/test images held out for validation (usage depends on val_split_mode)
  tiling:
    apply: false
    tile_size: null
    stride: null
    remove_border_count: 0
    use_random_tiling: False
    random_tile_count: 16

model:
  name: padim
  backbone: resnet18
  pre_trained: true
  layers:
    - layer1
    - layer2
    - layer3
  normalization_method: min_max # options: [none, min_max, cdf]

metrics:
  image:
    - F1Score
    - AUROC
  pixel:
    - F1Score
    - AUROC
  threshold:
    method: adaptive #options: [adaptive, manual]
    manual_image: null
    manual_pixel: null

visualization:
  show_images: False # show images on the screen
  save_images: True # save images to the file system
  log_images: True # log images to the available loggers (if any)
  image_save_path: null # path to which images will be saved
  mode: full # options: ["full", "simple"]

project:
  seed: 42
  path: ./results

logging:
  logger: [] # options: [comet, tensorboard, wandb, csv] or combinations.
  log_graph: false # Logs the model graph to respective logger.

optimization:
  export_mode: null #options: onnx, openvino

# PL Trainer Args. Don't add extra parameter here.
trainer:
  accelerator: auto # <"cpu", "gpu", "tpu", "ipu", "hpu", "auto">
  accumulate_grad_batches: 1
  amp_backend: native
  auto_lr_find: false
  auto_scale_batch_size: false
  auto_select_gpus: false
  benchmark: false
  check_val_every_n_epoch: 1 # Don't validate before extracting features.
  default_root_dir: null
  detect_anomaly: false
  deterministic: false
  devices: 1
  enable_checkpointing: true
  enable_model_summary: true
  enable_progress_bar: true
  fast_dev_run: false
  gpus: null # Set automatically
  gradient_clip_val: 0
  ipus: null
  limit_predict_batches: 1.0
  limit_test_batches: 1.0
  limit_train_batches: 1.0
  limit_val_batches: 1.0
  log_every_n_steps: 50
  max_epochs: 1
  max_steps: -1
  max_time: null
  min_epochs: null
  min_steps: null
  move_metrics_to_cpu: false
  multiple_trainloader_mode: max_size_cycle
  num_nodes: 1
  num_processes: null
  num_sanity_val_steps: 0
  overfit_batches: 0.0
  plugins: null
  precision: 32
  profiler: null
  reload_dataloaders_every_n_epochs: 0
  replace_sampler_ddp: true
  sync_batchnorm: false
  tpu_cores: null
  track_grad_norm: -1
  val_check_interval: 1.0 # Don't validate before extracting features.

Logs

ConfigAttributeError                      Traceback (most recent call last)
[<ipython-input-15-9682ddf2d22a>](https://localhost:8080/#) in <module>
----> 1 datamodule = get_datamodule(config)
      2 datamodule.setup()  # Downloads the dataset if it's not in the specified `root` directory
      3 datamodule.prepare_data()  # Create train/val/test/prediction sets.
      4 
      5 i, data = next(enumerate(datamodule.val_dataloader()))

8 frames
[/usr/local/lib/python3.8/dist-packages/omegaconf/dictconfig.py](https://localhost:8080/#) in _get_node(self, key, validate_access, validate_key, throw_on_missing_value, throw_on_missing_key)
    478         if value is None:
    479             if throw_on_missing_key:
--> 480                 raise ConfigKeyError(f"Missing key {key!s}")
    481         elif throw_on_missing_value and value._is_missing():
    482             raise MissingMandatoryValue("Missing mandatory value: $KEY")

ConfigAttributeError: Missing key val
    full_key: dataset.transform_config.val
    object_type=dict

Code of Conduct

samet-akcay commented 1 year ago

Hi @yjwong1999, we recently merged #863 that addressed jupyter-related issues. Can you pull the latest changes and try again please?

samet-akcay commented 1 year ago

Assuming that this has been resolved, I'm closing this issue. Feel free to re-open if you encounter any related issues.

yjwong1999 commented 1 year ago

Hi @samet-akcay

Thanks a lot for the solution! I have tried with the latest changes, and it works. Thanks a lot!