hcw-00 / PatchCore_anomaly_detection

Unofficial implementation of PatchCore anomaly detection
Apache License 2.0
317 stars 95 forks source link

train speed get more and more slowly #24

Closed XiaoPengZong closed 2 years ago

XiaoPengZong commented 2 years ago

Hi, I am trying to train the model in dataset, however I find that the speed is getting more and more slowly. I noticed that the embedding size is getting bigger, so whether we can change it? Thanks. image

SDJustus commented 2 years ago

In my opinion the training procedure of this model is intented to train for one epoch only. The minimax-facility location (kCenterGreedy here as approximation) doesn't make sense for more than one epoch (imo).

XiaoPengZong commented 2 years ago

So your mean is the only thing we should do is train one epoch for embedding file when we detect in new dataset?

SDJustus commented 2 years ago

yes, because the is not trained as i mentioned before. Procedure is as follows:

  1. get embedding vectors of layer 2 and 3 with inferencing the pretrained network
  2. concat these two vectors (with remaining w and h from layer 2)
  3. do this for all train_images and you get the Memory Bank M (refering to the paper)
  4. do a Sparse Random Projection (dimensionality reduction) for reduction of computation time
  5. do a minimax facility location to reduce the memory bank to the embedding_coreset Training Finished

Test:

  1. load the embedding coreset
  2. get knn with input image as queue vector and embedding coreset as "train" set of the knn
  3. compute anomaly score with formula given from the paper Finished

I hope this helps you

XiaoPengZong commented 2 years ago

Hi, @SDJustus Thanks for your help, I will test it.