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

[Bug] : Classification with Fastflow always return 'True' when predict 'Pred_label' (image_size makes un error) #1176

Closed papago2355 closed 1 year ago

papago2355 commented 1 year ago

Describe the bug

Hi. I am currently using custom dataset with fastflow+classification. I tried to predict 'pred_label' but it only returns 'True' even if I predict normal images.

Dataset

Other (please specify in the text field below)

Model

FastFlow

Steps to reproduce the behavior

Only change config file. And use google colab notebook based tutorial codes.

https://colab.research.google.com/drive/17Cwhg2H8JMBYhLBJvK01ZXKCP-XsIrM4?usp=sharing

Here is the link

Edit : it seems like, it is not working due to 'image_size' option in utils 'read_image'

I deleted that attribute and it somehow, returns correctly.

OS information

OS information:

Expected behavior

Expected to return 'False' if I predict normal images.

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

No response

Configuration YAML

dataset:
  name: belt
  root: ./datasets/belt
  format : folder
  normal_dir : ok
  abnormal_dir : ng
  mask : null
  normal_test_dir : null
  extensions : null
  task: classification
  train_batch_size: 32
  eval_batch_size: 32
  num_workers: 8
  image_size: 256 # dimensions to which images are resized (mandatory) options: [256, 256, 448, 384]
  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: fastflow
  backbone: resnet18 # 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
  hidden_ratio: 1.0 # options: [1.0, 1.0, 0.16, 0.16] - for each supported backbone
  conv3x3_only: True # options: [True, False, False, False] - for each supported backbone
  lr: 0.001
  weight_decay: 0.00001
  early_stopping:
    patience: 3
    metric: image_AUROC
    mode: max
  normalization_method: min_max # options: [null, min_max, cdf]

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

visualization:
  show_images: False # show images on the screen
  save_images: False # save images to the file system
  log_images: False # 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: openvino # options: torch, onnx, openvino

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

Logs

INFO:pytorch_lightning.utilities.rank_zero:The following callbacks returned in `LightningModule.configure_callbacks` will override existing callbacks passed to Trainer: EarlyStopping
WARNING:anomalib.utils.callbacks.metrics_configuration:Cannot perform pixel-level evaluation when task type is classification. Ignoring the following pixel-level metrics: ['F1Score', 'AUROC']
INFO:pytorch_lightning.accelerators.cuda:LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
Predicting DataLoader 0: 100%
1/1 [00:00<00:00, 6.63it/s]
tensor(True)


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
samet-akcay commented 1 year ago

Edit : it seems like, it is not working due to 'image_size' option in utils 'read_image'

This option is for prototyping new ideas. Your image size is already in your meta_data during the inference, so you don't need to resize it.

If removing image_size solves your problem, I will close this issue. Feel free to re-open if you are still having problems. Thanks!

rohitpotdukhe01 commented 5 months ago

Hi, I am facing the same issue. I couldn't understand from where did you delete the image_size. Can you please provide some more detail?

papago2355 commented 5 months ago

Hi, I am facing the same issue. I couldn't understand from where did you delete the image_size. Can you please provide some more detail?

Anomalib updated to the new version. 'read_image' now does not have image_size parameter.