sicara / easy-few-shot-learning

Ready-to-use code and tutorial notebooks to boost your way into few-shot learning for image classification.
MIT License
1.07k stars 147 forks source link

How to use Prototypical Networks in production? #128

Closed durach closed 11 months ago

durach commented 11 months ago

I learned and played with my_first_few_shot_classifier. Read some source code of the module. Great library, thanks a lot!

Problem

I should have spent more time researching the topic, but I would appreciate advice on the typical way of making predictions in the FSL world, especially with Prototypical Networks.

In my task, I have ~1000 classes in the support set and ~100 images (one at a time) in my query set. As usual, I need to predict a class name for each image from the query set.

My assumption

  1. Create prototypes of all images (mean of all embeddings per class)
  2. Calc Euclidean distance between the query image and each prototype
  3. Take the max score (min distance)

How can we help

  1. Is there something more efficient than what I described above?
  2. Let me know if there is something already implemented in the module, please;
ebennequin commented 11 months ago

Hi! Is there any reason why easyfsl.methods.PrototypicalNetworks would not be appropriate in your case?

Note that if you have a lot of classes, it may become suboptimal to compare each query image to each class prototype, and vector databases could help you gain in efficiency. However I recommend that you get things working without it at first.

durach commented 11 months ago

Thank you for getting back to me so quickly.

In general, am I right in my assumption that I need to run the model with these query images against a batch of support images?

Thank you. I'll check out easyfsl.methods.PrototypicalNetworks, as I see it is the more high-level implementation of the code in the notebook I looked at.

As for vector DB, probably you're right, but I need to have my prototype working at least)

ebennequin commented 11 months ago

I suggest you check this notebook which has the most efficient and recommended method for performing inference with prototypical classification.

durach commented 11 months ago

Thank you!