zqhang / AnomalyCLIP

Official implementation for AnomalyCLIP (ICLR 2024)
MIT License
257 stars 25 forks source link

Training Methodology Issue: Incorrect Dataset Mode #8

Closed mojtaba-nafez closed 5 months ago

mojtaba-nafez commented 5 months ago

I've encountered an issue in the paper's code regarding the training approach for the anomaly detector on the MVTec AD dataset. The problem lies in the train.py script at line 35 where the Dataset object for training is created without specifying mode="train":

train_data = Dataset(root=args.train_data_path, transform=preprocess, target_transform=target_transform, dataset_name=args.dataset)

This oversight leads to two critical problems:

  1. The model mistakenly uses the test set for training.
  2. The anomaly detection framework is deprived of abnormal data during training, yet it encounters anomalies during testing. This inconsistency suggests that the model might be functioning as a simple classifier rather than performing anomaly detection.

Could this be revised to ensure the correct dataset partitioning and training setup?

cescomuch commented 1 month ago

I have also encountered this behavior. My suspicion is that they specified mode="test" to use normal and abnormal images during training (many Anomaly Detection datasets have only normal images in the training set but normal and abnormal in the test set).

zqhang commented 1 month ago

Hi, I believe this point has already been clarified in the paper. We fine-tune AnomalyCLIP using an auxiliary dataset and then test it on other datasets in zero-shot manner. Regarding the decision to set the test mode during training, this is because the MVTec dataset does not provide anomaly samples in its training dataset for fine-tuning AnomalyCLIP.