How i can save feature vectors for each image in my folder

hi friends
I trained my model in the following way:
Now i want to seed my training data into this trained model again and extract the feature vector for each image so that its size is “embed-size” in my code. And then I want to save all these feature vectors in my hard disk .On the other hand, I have a lot of image folders and I want to save the image vectors in the way similar to those image folders and with the same names.

Pleas help me how to accomplish this via code?


Hey @romina.ui,

Why not just save the output of f_anc, f_pos, f_neg as numpy array using

I don’t need f_pos and f_neg after train my model. I want just f_nac for save my image. should i change my code?
for training stage and I select my training data as f_anc , f_pos and f_neg but for extract my feature vector and save them i want seed all images again to my trained model and save feature vectors in new folders that they have same names with my image folder

After training the model, you can redefine the forward function to return only f_nac. You can use “types” library to redefine the member functions of an existing object. Is this what you are looking for?

Yes .but I think my idea is not true . so I think I should load trained model without any change .
I write this code for load trained model with its weight but its not true.
Can you help me Please?

model.load_state_dict(torch.load(“trained model path” + “best weights path”))