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.4k stars 615 forks source link

[Bug]: The size of tensor a (4096) must match the size of tensor b (0) at non-singleton dimension 1 #2111

Open cjy513203427 opened 1 month ago

cjy513203427 commented 1 month ago

Describe the bug

Thanks for the great work! When I use the rkde model to train and test on the MVTec dataset with the category carpet, I get an error. I have this error with anomalib version 1.0.1 and 1.1.0.

Dataset

MVTec

Model

Other (please specify in the field below)

Steps to reproduce the behavior

When I use the rkde model to train and test on the MVTec dataset with the category carpet, I get this error. This is my bash.


datasets=('screw' 'pill' 'capsule' 'carpet' 'grid' 'tile' 'wood' 'zipper' 'cable' 'toothbrush' 'transistor' 'metal_nut' 'bottle' 'hazelnut' 'leather')
config_file="./configs/models/rkde.yaml"

for dataset in "${datasets[@]}"
do
    command="anomalib train --data anomalib.data.MVTec --data.category $dataset --config $config_file"
    echo "Running command: $command"
    # Excute command
    $command
done

Only this category (carpet) is with bugs.

anomalib train --data anomalib.data.MVTec --data.category carpet --config ./configs/models/rkde.yaml

OS information

OS information:

Expected behavior

It shall train and test without error.

Screenshots

No response

Pip/GitHub

pip

What version/branch did you use?

1.1.0

Configuration YAML

model:
  class_path: anomalib.models.Rkde
  init_args:
    roi_stage: RCNN
    roi_score_threshold: 0.001
    min_box_size: 25
    iou_threshold: 0.3
    max_detections_per_image: 100
    n_pca_components: 16
    feature_scaling_method: SCALE
    max_training_points: 40000

metrics:
  pixel:
    - AUROC
    - PRO
  image:
    - AUROC
    - PRO

task: detection

Logs

(IADBE) jinyao@jinyao-System-Product-Name:~/PycharmProjects/IADBE$ 
(IADBE) jinyao@jinyao-System-Product-Name:~/PycharmProjects/IADBE$ anomalib train --data anomalib.data.MVTec --data.category carpet --config ./configs/models/rkde.yaml
2024-06-04 17:50:36,840 - anomalib.utils.config - WARNING - Anomalib currently does not support multi-gpu training. Setting devices to 1.
[06/04/24 17:50:36] WARNING  Anomalib currently does not support multi-gpu training. Setting devices to 1.                                                                                                    config.py:262
2024-06-04 17:50:36,855 - anomalib.models.components.base.anomaly_module - INFO - Initializing Rkde model.
                    INFO     Initializing Rkde model.                                                                                                                                                  anomaly_module.py:42
/home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
  warnings.warn(
/home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=FasterRCNN_ResNet50_FPN_Weights.COCO_V1`. You can also use `weights=FasterRCNN_ResNet50_FPN_Weights.DEFAULT` to get the most up-to-date weights.
  warnings.warn(msg)
2024-06-04 17:50:37,675 - anomalib.callbacks - INFO - Loading the callbacks
[06/04/24 17:50:37] INFO     Loading the callbacks                                                                                                                                                           __init__.py:43
2024-06-04 17:50:37,676 - anomalib.engine.engine - INFO - Overriding gradient_clip_val from None with 0 for Rkde
                    INFO     Overriding gradient_clip_val from None with 0 for Rkde                                                                                                                            engine.py:84
2024-06-04 17:50:37,677 - anomalib.engine.engine - INFO - Overriding max_epochs from None with 1 for Rkde
                    INFO     Overriding max_epochs from None with 1 for Rkde                                                                                                                                   engine.py:84
2024-06-04 17:50:37,678 - anomalib.engine.engine - INFO - Overriding num_sanity_val_steps from None with 0 for Rkde
                    INFO     Overriding num_sanity_val_steps from None with 0 for Rkde                                                                                                                         engine.py:84
2024-06-04 17:50:37,757 - lightning.pytorch.utilities.rank_zero - INFO - Trainer already configured with model summary callbacks: [<class 'lightning.pytorch.callbacks.rich_model_summary.RichModelSummary'>]. Skipping setting a default `ModelSummary` callback.
[06/04/24 17:50:37] INFO     Trainer already configured with model summary callbacks: [<class 'lightning.pytorch.callbacks.rich_model_summary.RichModelSummary'>]. Skipping setting a default               rank_zero.py:63
                             `ModelSummary` callback.                                                                                                                                                                      
2024-06-04 17:50:37,765 - lightning.pytorch.utilities.rank_zero - INFO - GPU available: True (cuda), used: True
                    INFO     GPU available: True (cuda), used: True                                                                                                                                         rank_zero.py:63
2024-06-04 17:50:37,765 - lightning.pytorch.utilities.rank_zero - INFO - TPU available: False, using: 0 TPU cores
                    INFO     TPU available: False, using: 0 TPU cores                                                                                                                                       rank_zero.py:63
2024-06-04 17:50:37,766 - lightning.pytorch.utilities.rank_zero - INFO - IPU available: False, using: 0 IPUs
                    INFO     IPU available: False, using: 0 IPUs                                                                                                                                            rank_zero.py:63
2024-06-04 17:50:37,767 - lightning.pytorch.utilities.rank_zero - INFO - HPU available: False, using: 0 HPUs
                    INFO     HPU available: False, using: 0 HPUs                                                                                                                                            rank_zero.py:63
2024-06-04 17:50:37,768 - anomalib.models.components.base.anomaly_module - WARNING - No implementation of `configure_transforms` was provided in the Lightning model. Using default transforms from the base class. This may not be suitable for your use case. Please override `configure_transforms` in your model.
                    WARNING  No implementation of `configure_transforms` was provided in the Lightning model. Using default transforms from the base class. This may not be suitable for your use     anomaly_module.py:235
                             case. Please override `configure_transforms` in your model.                                                                                                                                   
2024-06-04 17:50:37,769 - anomalib.data.image.mvtec - INFO - Found the dataset.
                    INFO     Found the dataset.                                                                                                                                                                mvtec.py:412
2024-06-04 17:50:37,806 - lightning.pytorch.utilities.rank_zero - INFO - You are using a CUDA device ('NVIDIA GeForce RTX 3090') that has Tensor Cores. To properly utilize them, you should set `torch.set_float32_matmul_precision('medium' | 'high')` which will trade-off precision for performance. For more details, read https://pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html#torch.set_float32_matmul_precision
                    INFO     You are using a CUDA device ('NVIDIA GeForce RTX 3090') that has Tensor Cores. To properly utilize them, you should set `torch.set_float32_matmul_precision('medium' |         rank_zero.py:63
                             'high')` which will trade-off precision for performance. For more details, read                                                                                                               
                             https://pytorch.org/docs/stable/generated/torch.set_float32_matmul_precision.html#torch.set_float32_matmul_precision                                                                          
2024-06-04 17:50:38,042 - lightning.pytorch.accelerators.cuda - INFO - LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
[06/04/24 17:50:38] INFO     LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]                                                                                                                                           cuda.py:58
/home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/core/optimizer.py:180: `LightningModule.configure_optimizers` returned `None`, this fit will run with no optimizer
┏━━━┳━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃   ┃ Name                  ┃ Type                     ┃ Params ┃
┡━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ 0 │ model                 │ RkdeModel                │ 98.8 M │
│ 1 │ _transform            │ Compose                  │      0 │
│ 2 │ normalization_metrics │ MinMax                   │      0 │
│ 3 │ image_threshold       │ F1AdaptiveThreshold      │      0 │
│ 4 │ pixel_threshold       │ F1AdaptiveThreshold      │      0 │
│ 5 │ image_metrics         │ AnomalibMetricCollection │      0 │
│ 6 │ pixel_metrics         │ AnomalibMetricCollection │      0 │
└───┴───────────────────────┴──────────────────────────┴────────┘
Trainable params: 98.5 M                                                                                                                                                                                                   
Non-trainable params: 222 K                                                                                                                                                                                                
Total params: 98.8 M                                                                                                                                                                                                       
Total estimated model params size (MB): 395                                                                                                                                                                                
/home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torchvision/transforms/functional.py:1603: UserWarning: The default value of the antialias parameter of all the resizing transforms (Resize(), 
RandomResizedCrop(), etc.) will change from None to True in v0.17, in order to be consistent across the PIL and Tensor backends. To suppress this warning, directly pass antialias=True (recommended, future default), 
antialias=None (current default, which means False for Tensors and True for PIL), or antialias=False (only works on Tensors - PIL will still use antialiasing). This also applies if you are using the inference transforms
from the models weights: update the call to weights.transforms(antialias=True).
  warnings.warn(
/home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/optimization/automatic.py:129: `training_step` returned `None`. If this was on purpose, ignore this warning...
Epoch 0/0  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9/9 0:00:07 • 0:00:00 1.68it/s  2024-06-04 17:50:46,253 - anomalib.models.image.rkde.lightning_model - INFO - Fitting a KDE model to the embedding collected from the training set.
[06/04/24 17:50:46] INFO     Fitting a KDE model to the embedding collected from the training set.                                                                                                   lightning_model.py:100
Epoch 0/0  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9/9 0:00:07 • 0:00:00 1.68it/s  2024-06-04 17:50:46,256 - anomalib.models.components.classification.kde_classifier - INFO - Not enough features to commit. Not making a model.
                    INFO     Not enough features to commit. Not making a model.                                                                                                                        kde_classifier.py:92
Epoch 0/0  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9/9 0:00:07 • 0:00:00 1.68it/s  
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/jinyao/anaconda3/envs/IADBE/bin/anomalib:8 in <module>                                     │
│                                                                                                  │
│   5 from anomalib.cli.cli import main                                                            │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(main())                                                                         │
│   9                                                                                              │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/cli/cli.py:486 in main   │
│                                                                                                  │
│   483 def main() -> None:                                                                        │
│   484 │   """Trainer via Anomalib CLI."""                                                        │
│   485 │   configure_logger()                                                                     │
│ ❱ 486 │   AnomalibCLI()                                                                          │
│   487                                                                                            │
│   488                                                                                            │
│   489 if __name__ == "__main__":                                                                 │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/cli/cli.py:65 in         │
│ __init__                                                                                         │
│                                                                                                  │
│    62 │   │   │   self.before_instantiate_classes()                                              │
│    63 │   │   │   self.instantiate_classes()                                                     │
│    64 │   │   if run:                                                                            │
│ ❱  65 │   │   │   self._run_subcommand()                                                         │
│    66 │                                                                                          │
│    67 │   def init_parser(self, **kwargs) -> ArgumentParser:                                     │
│    68 │   │   """Method that instantiates the argument parser."""                                │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/cli/cli.py:365 in        │
│ _run_subcommand                                                                                  │
│                                                                                                  │
│   362 │   │   elif self.config["subcommand"] in (*self.subcommands(), "train", "export", "pred   │
│   363 │   │   │   fn = getattr(self.engine, self.subcommand)                                     │
│   364 │   │   │   fn_kwargs = self._prepare_subcommand_kwargs(self.subcommand)                   │
│ ❱ 365 │   │   │   fn(**fn_kwargs)                                                                │
│   366 │   │   elif PIPELINE_REGISTRY is not None and self.subcommand in pipeline_subcommands()   │
│   367 │   │   │   run_pipeline(self.config)                                                      │
│   368 │   │   else:                                                                              │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/engine/engine.py:862 in  │
│ train                                                                                            │
│                                                                                                  │
│    859 │   │   │   # if the model is zero-shot or few-shot, we only need to run validate for no  │
│    860 │   │   │   self.trainer.validate(model, val_dataloaders, None, verbose=False, datamodul  │
│    861 │   │   else:                                                                             │
│ ❱  862 │   │   │   self.trainer.fit(model, train_dataloaders, val_dataloaders, datamodule, ckpt  │
│    863 │   │   self.trainer.test(model, test_dataloaders, ckpt_path=ckpt_path, datamodule=datam  │
│    864 │                                                                                         │
│    865 │   def export(                                                                           │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer │
│ .py:544 in fit                                                                                   │
│                                                                                                  │
│    541 │   │   self.state.fn = TrainerFn.FITTING                                                 │
│    542 │   │   self.state.status = TrainerStatus.RUNNING                                         │
│    543 │   │   self.training = True                                                              │
│ ❱  544 │   │   call._call_and_handle_interrupt(                                                  │
│    545 │   │   │   self, self._fit_impl, model, train_dataloaders, val_dataloaders, datamodule,  │
│    546 │   │   )                                                                                 │
│    547                                                                                           │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/trainer/call.py │
│ :44 in _call_and_handle_interrupt                                                                │
│                                                                                                  │
│    41 │   try:                                                                                   │
│    42 │   │   if trainer.strategy.launcher is not None:                                          │
│    43 │   │   │   return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer,    │
│ ❱  44 │   │   return trainer_fn(*args, **kwargs)                                                 │
│    45 │                                                                                          │
│    46 │   except _TunerExitException:                                                            │
│    47 │   │   _call_teardown_hook(trainer)                                                       │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer │
│ .py:580 in _fit_impl                                                                             │
│                                                                                                  │
│    577 │   │   │   model_provided=True,                                                          │
│    578 │   │   │   model_connected=self.lightning_module is not None,                            │
│    579 │   │   )                                                                                 │
│ ❱  580 │   │   self._run(model, ckpt_path=ckpt_path)                                             │
│    581 │   │                                                                                     │
│    582 │   │   assert self.state.stopped                                                         │
│    583 │   │   self.training = False                                                             │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer │
│ .py:989 in _run                                                                                  │
│                                                                                                  │
│    986 │   │   # ----------------------------                                                    │
│    987 │   │   # RUN THE TRAINER                                                                 │
│    988 │   │   # ----------------------------                                                    │
│ ❱  989 │   │   results = self._run_stage()                                                       │
│    990 │   │                                                                                     │
│    991 │   │   # ----------------------------                                                    │
│    992 │   │   # POST-Training CLEAN UP                                                          │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/trainer/trainer │
│ .py:1035 in _run_stage                                                                           │
│                                                                                                  │
│   1032 │   │   │   with isolate_rng():                                                           │
│   1033 │   │   │   │   self._run_sanity_check()                                                  │
│   1034 │   │   │   with torch.autograd.set_detect_anomaly(self._detect_anomaly):                 │
│ ❱ 1035 │   │   │   │   self.fit_loop.run()                                                       │
│   1036 │   │   │   return None                                                                   │
│   1037 │   │   raise RuntimeError(f"Unexpected state {self.state}")                              │
│   1038                                                                                           │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/fit_loop. │
│ py:202 in run                                                                                    │
│                                                                                                  │
│   199 │   │   while not self.done:                                                               │
│   200 │   │   │   try:                                                                           │
│   201 │   │   │   │   self.on_advance_start()                                                    │
│ ❱ 202 │   │   │   │   self.advance()                                                             │
│   203 │   │   │   │   self.on_advance_end()                                                      │
│   204 │   │   │   │   self._restarting = False                                                   │
│   205 │   │   │   except StopIteration:                                                          │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/fit_loop. │
│ py:359 in advance                                                                                │
│                                                                                                  │
│   356 │   │   │   )                                                                              │
│   357 │   │   with self.trainer.profiler.profile("run_training_epoch"):                          │
│   358 │   │   │   assert self._data_fetcher is not None                                          │
│ ❱ 359 │   │   │   self.epoch_loop.run(self._data_fetcher)                                        │
│   360 │                                                                                          │
│   361 │   def on_advance_end(self) -> None:                                                      │
│   362 │   │   trainer = self.trainer                                                             │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/training_ │
│ epoch_loop.py:137 in run                                                                         │
│                                                                                                  │
│   134 │   │   while not self.done:                                                               │
│   135 │   │   │   try:                                                                           │
│   136 │   │   │   │   self.advance(data_fetcher)                                                 │
│ ❱ 137 │   │   │   │   self.on_advance_end(data_fetcher)                                          │
│   138 │   │   │   │   self._restarting = False                                                   │
│   139 │   │   │   except StopIteration:                                                          │
│   140 │   │   │   │   break                                                                      │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/training_ │
│ epoch_loop.py:285 in on_advance_end                                                              │
│                                                                                                  │
│   282 │   │   │   │   # clear gradients to not leave any unused memory during validation         │
│   283 │   │   │   │   call._call_lightning_module_hook(self.trainer, "on_validation_model_zero   │
│   284 │   │   │                                                                                  │
│ ❱ 285 │   │   │   self.val_loop.run()                                                            │
│   286 │   │   │   self.trainer.training = True                                                   │
│   287 │   │   │   self.trainer._logger_connector._first_loop_iter = first_loop_iter              │
│   288                                                                                            │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/utilities │
│ .py:182 in _decorator                                                                            │
│                                                                                                  │
│   179 │   │   else:                                                                              │
│   180 │   │   │   context_manager = torch.no_grad                                                │
│   181 │   │   with context_manager():                                                            │
│ ❱ 182 │   │   │   return loop_run(self, *args, **kwargs)                                         │
│   183 │                                                                                          │
│   184 │   return _decorator                                                                      │
│   185                                                                                            │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/evaluatio │
│ n_loop.py:134 in run                                                                             │
│                                                                                                  │
│   131 │   │   │   │   previous_dataloader_idx = dataloader_idx                                   │
│   132 │   │   │   │   self.batch_progress.is_last_batch = data_fetcher.done                      │
│   133 │   │   │   │   # run step hooks                                                           │
│ ❱ 134 │   │   │   │   self._evaluation_step(batch, batch_idx, dataloader_idx, dataloader_iter)   │
│   135 │   │   │   except StopIteration:                                                          │
│   136 │   │   │   │   # this needs to wrap the `*_step` call too (not just `next`) for `datalo   │
│   137 │   │   │   │   break                                                                      │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/loops/evaluatio │
│ n_loop.py:391 in _evaluation_step                                                                │
│                                                                                                  │
│   388 │   │   │   if not using_dataloader_iter                                                   │
│   389 │   │   │   else (dataloader_iter,)                                                        │
│   390 │   │   )                                                                                  │
│ ❱ 391 │   │   output = call._call_strategy_hook(trainer, hook_name, *step_args)                  │
│   392 │   │                                                                                      │
│   393 │   │   self.batch_progress.increment_processed()                                          │
│   394                                                                                            │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/trainer/call.py │
│ :309 in _call_strategy_hook                                                                      │
│                                                                                                  │
│   306 │   │   return None                                                                        │
│   307 │                                                                                          │
│   308 │   with trainer.profiler.profile(f"[Strategy]{trainer.strategy.__class__.__name__}.{hoo   │
│ ❱ 309 │   │   output = fn(*args, **kwargs)                                                       │
│   310 │                                                                                          │
│   311 │   # restore current_fx when nested context                                               │
│   312 │   pl_module._current_fx_name = prev_fx_name                                              │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/lightning/pytorch/strategies/stra │
│ tegy.py:403 in validation_step                                                                   │
│                                                                                                  │
│   400 │   │   with self.precision_plugin.val_step_context():                                     │
│   401 │   │   │   if self.model != self.lightning_module:                                        │
│   402 │   │   │   │   return self._forward_redirection(self.model, self.lightning_module, "val   │
│ ❱ 403 │   │   │   return self.lightning_module.validation_step(*args, **kwargs)                  │
│   404 │                                                                                          │
│   405 │   def test_step(self, *args: Any, **kwargs: Any) -> STEP_OUTPUT:                         │
│   406 │   │   """The actual test step.                                                           │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/models/image/rkde/lightn │
│ ing_model.py:119 in validation_step                                                              │
│                                                                                                  │
│   116 │   │   del args, kwargs  # These variables are not used.                                  │
│   117 │   │                                                                                      │
│   118 │   │   # get batched model predictions                                                    │
│ ❱ 119 │   │   boxes, scores = self.model(batch["image"])                                         │
│   120 │   │                                                                                      │
│   121 │   │   # convert batched predictions to list format                                       │
│   122 │   │   image: torch.Tensor = batch["image"]                                               │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torch/nn/modules/module.py:1518   │
│ in _wrapped_call_impl                                                                            │
│                                                                                                  │
│   1515 │   │   if self._compiled_call_impl is not None:                                          │
│   1516 │   │   │   return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]        │
│   1517 │   │   else:                                                                             │
│ ❱ 1518 │   │   │   return self._call_impl(*args, **kwargs)                                       │
│   1519 │                                                                                         │
│   1520 │   def _call_impl(self, *args, **kwargs):                                                │
│   1521 │   │   forward_call = (self._slow_forward if torch._C._get_tracing_state() else self.fo  │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torch/nn/modules/module.py:1527   │
│ in _call_impl                                                                                    │
│                                                                                                  │
│   1524 │   │   if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks   │
│   1525 │   │   │   │   or _global_backward_pre_hooks or _global_backward_hooks                   │
│   1526 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                   │
│ ❱ 1527 │   │   │   return forward_call(*args, **kwargs)                                          │
│   1528 │   │                                                                                     │
│   1529 │   │   try:                                                                              │
│   1530 │   │   │   result = None                                                                 │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/models/image/rkde/torch_ │
│ model.py:113 in forward                                                                          │
│                                                                                                  │
│   110 │   │   │   return features                                                                │
│   111 │   │                                                                                      │
│   112 │   │   # 3. apply density estimation                                                      │
│ ❱ 113 │   │   scores = self.classifier(features)                                                 │
│   114 │   │                                                                                      │
│   115 │   │   return rois, scores                                                                │
│   116                                                                                            │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torch/nn/modules/module.py:1518   │
│ in _wrapped_call_impl                                                                            │
│                                                                                                  │
│   1515 │   │   if self._compiled_call_impl is not None:                                          │
│   1516 │   │   │   return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]        │
│   1517 │   │   else:                                                                             │
│ ❱ 1518 │   │   │   return self._call_impl(*args, **kwargs)                                       │
│   1519 │                                                                                         │
│   1520 │   def _call_impl(self, *args, **kwargs):                                                │
│   1521 │   │   forward_call = (self._slow_forward if torch._C._get_tracing_state() else self.fo  │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/torch/nn/modules/module.py:1527   │
│ in _call_impl                                                                                    │
│                                                                                                  │
│   1524 │   │   if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks   │
│   1525 │   │   │   │   or _global_backward_pre_hooks or _global_backward_hooks                   │
│   1526 │   │   │   │   or _global_forward_hooks or _global_forward_pre_hooks):                   │
│ ❱ 1527 │   │   │   return forward_call(*args, **kwargs)                                          │
│   1528 │   │                                                                                     │
│   1529 │   │   try:                                                                              │
│   1530 │   │   │   result = None                                                                 │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/models/components/classi │
│ fication/kde_classifier.py:161 in forward                                                        │
│                                                                                                  │
│   158 │                                                                                          │
│   159 │   def forward(self, features: torch.Tensor) -> torch.Tensor:                             │
│   160 │   │   """Make predictions on extracted features."""                                      │
│ ❱ 161 │   │   return self.predict(features)                                                      │
│   162                                                                                            │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/models/components/classi │
│ fication/kde_classifier.py:156 in predict                                                        │
│                                                                                                  │
│   153 │   │   Returns:                                                                           │
│   154 │   │     Detection probabilities                                                          │
│   155 │   │   """                                                                                │
│ ❱ 156 │   │   scores = self.compute_kde_scores(features, as_log_likelihood=True)                 │
│   157 │   │   return self.compute_probabilities(scores)                                          │
│   158 │                                                                                          │
│   159 │   def forward(self, features: torch.Tensor) -> torch.Tensor:                             │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/models/components/classi │
│ fication/kde_classifier.py:122 in compute_kde_scores                                             │
│                                                                                                  │
│   119 │   │   Returns:                                                                           │
│   120 │   │   │   (torch.Tensor): Score                                                          │
│   121 │   │   """                                                                                │
│ ❱ 122 │   │   features = self.pca_model.transform(features)                                      │
│   123 │   │   features, _ = self.pre_process(features, self.max_length)                          │
│   124 │   │   # Scores are always assumed to be passed as a density                              │
│   125 │   │   kde_scores = self.kde_model(features)                                              │
│                                                                                                  │
│ /home/jinyao/anaconda3/envs/IADBE/lib/python3.10/site-packages/anomalib/models/components/dimens │
│ ionality_reduction/pca.py:129 in transform                                                       │
│                                                                                                  │
│   126 │   │   │   >>> transformed_embedding.shape                                                │
│   127 │   │   │   torch.Size([1000, 2])                                                          │
│   128 │   │   """                                                                                │
│ ❱ 129 │   │   features -= self.mean                                                              │
│   130 │   │   return torch.matmul(features, self.singular_vectors)                               │
│   131 │                                                                                          │
│   132 │   def inverse_transform(self, features: torch.Tensor) -> torch.Tensor:                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
RuntimeError: The size of tensor a (4096) must match the size of tensor b (0) at non-singleton dimension 1
(IADBE) jinyao@jinyao-System-Product-Name:~/PycharmProjects/IADBE$ pip list
Package                   Version
------------------------- --------------
about-time                4.2.1
absl-py                   2.1.0
aiofiles                  23.2.1
aiohttp                   3.9.5
aiosignal                 1.3.1
alive-progress            3.1.5
altair                    5.3.0
annotated-types           0.7.0
anomalib                  1.1.0
antlr4-python3-runtime    4.9.3
anyio                     4.3.0
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 2.4.1
async-lru                 2.0.4
async-timeout             4.0.3
attrs                     23.2.0
autograd                  1.6.2
av                        12.0.0
Babel                     2.15.0
beautifulsoup4            4.12.3
bleach                    6.1.0
cachetools                5.3.3
certifi                   2024.2.2
cffi                      1.16.0
cfgv                      3.4.0
chardet                   5.2.0
charset-normalizer        3.3.2
click                     8.1.7
cma                       3.2.2
colorama                  0.4.6
comet-ml                  3.42.1
comm                      0.2.2
configobj                 5.0.8
contourpy                 1.2.1
coverage                  7.5.1
cycler                    0.12.1
debugpy                   1.8.1
decorator                 5.1.1
defusedxml                0.7.1
Deprecated                1.2.14
dill                      0.3.8
distlib                   0.3.8
dnspython                 2.6.1
docker-pycreds            0.4.0
docstring_parser          0.16
dulwich                   0.22.1
einops                    0.8.0
email_validator           2.1.1
everett                   3.1.0
exceptiongroup            1.2.1
execnet                   2.1.1
executing                 2.0.1
fastapi                   0.111.0
fastapi-cli               0.0.4
fastjsonschema            2.19.1
ffmpy                     0.3.2
filelock                  3.14.0
fonttools                 4.51.0
fqdn                      1.5.1
FrEIA                     0.2
frozenlist                1.4.1
fsspec                    2024.5.0
ftfy                      6.2.0
future                    1.0.0
gitdb                     4.0.11
GitPython                 3.1.43
gradio                    4.31.5
gradio_client             0.16.4
grapheme                  0.6.0
grpcio                    1.64.0
h11                       0.14.0
httpcore                  1.0.5
httptools                 0.6.1
httpx                     0.27.0
huggingface-hub           0.23.1
identify                  2.5.36
idna                      3.7
imageio                   2.34.1
imgaug                    0.4.0
importlib_resources       6.4.0
iniconfig                 2.0.0
ipykernel                 6.29.4
ipython                   8.24.0
ipywidgets                8.1.2
isoduration               20.11.0
jedi                      0.19.1
Jinja2                    3.1.4
joblib                    1.4.2
json5                     0.9.25
jsonargparse              4.29.0
jsonpointer               2.4
jsonschema                4.22.0
jsonschema-specifications 2023.12.1
jstyleson                 0.0.2
jupyter_client            8.6.2
jupyter_core              5.7.2
jupyter-events            0.10.0
jupyter-lsp               2.2.5
jupyter_server            2.14.0
jupyter_server_terminals  0.5.3
jupyterlab                4.2.1
jupyterlab_pygments       0.3.0
jupyterlab_server         2.27.2
jupyterlab_widgets        3.0.10
kiwisolver                1.4.5
kornia                    0.6.9
lazy_loader               0.4
lightning                 2.1.4
lightning-utilities       0.11.2
Markdown                  3.6
markdown-it-py            3.0.0
MarkupSafe                2.1.5
matplotlib                3.9.0
matplotlib-inline         0.1.7
mdurl                     0.1.2
mistune                   3.0.2
mpmath                    1.3.0
multidict                 6.0.5
natsort                   8.4.0
nbclient                  0.10.0
nbconvert                 7.16.4
nbformat                  5.10.4
nest-asyncio              1.6.0
networkx                  3.1
ninja                     1.11.1.1
nncf                      2.10.0
nodeenv                   1.8.0
notebook                  7.2.0
notebook_shim             0.2.4
numpy                     1.26.4
omegaconf                 2.3.0
onnx                      1.16.1
open-clip-torch           2.24.0
opencv-python             4.9.0.80
openvino                  2024.1.0
openvino-dev              2024.1.0
openvino-telemetry        2024.1.0
orjson                    3.10.3
overrides                 7.7.0
packaging                 24.0
pandas                    2.2.2
pandocfilters             1.5.1
parso                     0.8.4
pathtools                 0.1.2
pexpect                   4.9.0
pillow                    10.3.0
pip                       24.0
platformdirs              4.2.2
pluggy                    1.5.0
pre-commit                3.7.1
prometheus_client         0.20.0
promise                   2.3
prompt-toolkit            3.0.43
protobuf                  3.20.3
psutil                    5.9.8
ptyprocess                0.7.0
pure-eval                 0.2.2
pycparser                 2.22
pydantic                  2.7.1
pydantic_core             2.18.2
pydot                     2.0.0
pydub                     0.25.1
Pygments                  2.18.0
pymoo                     0.6.1.1
pyparsing                 3.1.2
pyproject-api             1.6.1
pytest                    8.2.1
pytest-cov                5.0.0
pytest-mock               3.14.0
pytest-sugar              1.0.0
pytest-xdist              3.6.1
python-box                6.1.0
python-dateutil           2.9.0.post0
python-dotenv             1.0.1
python-json-logger        2.0.7
python-multipart          0.0.9
pytorch-lightning         2.2.5
pytz                      2024.1
PyYAML                    6.0.1
pyzmq                     26.0.3
referencing               0.35.1
regex                     2024.5.15
requests                  2.32.2
requests-toolbelt         1.0.0
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rich                      13.7.1
rich-argparse             1.4.0
rpds-py                   0.18.1
ruff                      0.4.5
scikit-image              0.23.2
scikit-learn              1.5.0
scipy                     1.13.1
semantic-version          2.10.0
Send2Trash                1.8.3
sentencepiece             0.2.0
sentry-sdk                2.3.1
setproctitle              1.3.3
setuptools                69.5.1
shapely                   2.0.4
shellingham               1.5.4
shortuuid                 1.0.13
simplejson                3.19.2
six                       1.16.0
smmap                     5.0.1
sniffio                   1.3.1
soupsieve                 2.5
stack-data                0.6.3
starlette                 0.37.2
sympy                     1.12
tabulate                  0.9.0
tensorboard               2.16.2
tensorboard-data-server   0.7.2
termcolor                 2.4.0
terminado                 0.18.1
threadpoolctl             3.5.0
tifffile                  2024.5.22
timm                      0.6.13
tinycss2                  1.3.0
tomli                     2.0.1
tomlkit                   0.12.0
toolz                     0.12.1
torch                     2.1.2+cu121
torchmetrics              1.4.0.post0
torchvision               0.16.2+cu121
tornado                   6.4
tox                       4.15.0
tqdm                      4.66.4
traitlets                 5.14.3
triton                    2.1.0
typer                     0.12.3
types-python-dateutil     2.9.0.20240316
typeshed_client           2.5.1
typing_extensions         4.12.0
tzdata                    2024.1
ujson                     5.10.0
uri-template              1.3.0
urllib3                   2.2.1
uvicorn                   0.29.0
uvloop                    0.19.0
virtualenv                20.26.2
wandb                     0.12.17
watchfiles                0.21.0
wcwidth                   0.2.13
webcolors                 1.13
webencodings              0.5.1
websocket-client          1.8.0
websockets                11.0.3
Werkzeug                  3.0.3
wheel                     0.43.0
widgetsnbextension        4.0.10
wrapt                     1.16.0
wurlitzer                 3.1.0
yarl                      1.9.4

Code of Conduct

julilien commented 3 weeks ago

This is also happening for Padim, the mean of the internal self.gaussian is not matching the expected input, for instance in the ONNX export.

cjy513203427 commented 3 weeks ago

This is also happening for Padim, the mean of the internal self.gaussian is not matching the expected input, for instance in the ONNX export.

Thanks for commenting. But in my case. When I use the Padim model to train and test on the MVTec dataset with the carpet category, it runs without errors. Do you use API or bash?