hcw-00 / PatchCore_anomaly_detection

Unofficial implementation of PatchCore anomaly detection
Apache License 2.0
320 stars 92 forks source link

Attribute Error while running test #42

Open svmaskery opened 2 years ago

svmaskery commented 2 years ago

There is an issue while running the test phase with the given code according to the instructions provided. Train phase runs without any issues but test phase runs into error. python train.py --phase test --dataset_path mvt_data --category capsule --project_root_path ./

Error:

File "train.py", line 442, in <module>
    trainer.test(model)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 911, in test
    return self._call_and_handle_interrupt(self._test_impl, model, dataloaders, ckpt_path, verbose, datamodule)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 685, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 954, in _test_impl
    results = self._run(model, ckpt_path=self.tested_ckpt_path)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 1199, in _run
    self._dispatch()
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 1275, in _dispatch
    self.training_type_plugin.start_evaluating(self)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/plugins/training_type/training_type_plugin.py", line 206, in start_evaluating
    self._results = trainer.run_stage()
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 1286, in run_stage
    return self._run_evaluate()
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 1334, in _run_evaluate
    eval_loop_results = self._evaluation_loop.run()
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/loops/base.py", line 140, in run
    self.on_run_start(*args, **kwargs)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py", line 96, in on_run_start
    self._on_evaluation_start()
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py", line 178, in _on_evaluation_start
    self.trainer.call_hook("on_test_start", *args, **kwargs)
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/pytorch_lightning/trainer/trainer.py", line 1501, in call_hook
    output = model_fx(*args, **kwargs)
  File "train.py", line 329, in on_test_start
    self.index = faiss.read_index(os.path.join(self.embedding_dir_path,'index.faiss'))
  File "/home/shreevijay/anaconda3/envs/patch_unoff/lib/python3.6/site-packages/torch/nn/modules/module.py", line 948, in __getattr__
    type(self).__name__, name))
AttributeError: 'STPM' object has no attribute 'embedding_dir_path'`