rvorias / ind_knn_ad

Vanilla torch and timm industrial knn-based anomaly detection for images.
https://share.streamlit.io/rvorias/ind_knn_ad
MIT License
147 stars 49 forks source link

Please tell me how to extract features from training data #34

Open kirorotarzan opened 1 month ago

kirorotarzan commented 1 month ago

Excuse me, I need your help. I have modified a program based on a Streamlit application to run it as a command-line interface (CUI). As an additional process, I want to implement a feature where the extracted features of the training data images can be saved as data (or a model?) and then reloaded when the program is executed again. However, as I am a beginner, I am struggling to implement this properly. I would appreciate it if you could give me some advice. Thank you.

rvorias commented 1 month ago

Hi, do you want to save the raw features (e.g. resnet50 features) or the features in the format of a specific approach? (e.g. spade features, padim features etc)

kirorotarzan commented 1 month ago

Thank you for your message. If possible, I would like to obtain the features of PatchCore. Best regards.

kirorotarzan commented 1 month ago

Excuse me. I've been doing some research, and is it correct to assume that I should use torch.save() to save the model?

rvorias commented 1 month ago

Hey, over the weekend I started working on a .export method for spade and patchcore, but for patchcore it's only the torchscript that gets exported, not yet the onnx format. Need to take a further look at that.

check out the test_patchcore.py file for work so far

https://github.com/rvorias/ind_knn_ad/blob/fbea993f3b4b61c9667ec9a22b76db3174f5263b/tests/test_patchcore.py#L23:L48

kirorotarzan commented 1 month ago

Thank you for your response and handling. I have reviewed the code. Personally, if it is possible to save the model in a .pt file and load that .pt file for inference during the next program execution, then using .onnx files is not particularly necessary