pytorch / serve

Serve, optimize and scale PyTorch models in production
https://pytorch.org/serve/
Apache License 2.0
4.23k stars 864 forks source link

Is it possible to use torch serve for deploying a Face Recognition model? #1921

Closed VikasNeoito closed 2 years ago

VikasNeoito commented 2 years ago

Hi, I am wondering whether I can use TorchServe to deploy a PyTorch FaceNet model. How do I set something that needs to take an image, pass it through the model to get the encodings, and then compare them to every image encoding in the database and output the closest one.? Which is the most efficient way to do this?

samils7 commented 2 years ago

I deployed a similar workflow with torchserve and working pretty well. This Workflow simply needs 3 components (torchserve models)

  1. Face Detector: inputs an image path and download it (maybe save to disk for later use), detect faces and pass face bbox coordinates in a dictionary to the next model.
  2. Feature Extractor: inputs the same image path and crops face boxes on it, batch all faces and extract face features. Adding feature vectors (embeddings) to dict and pass to the next.
  3. Database-KNN: Gets embeddings and query to a database, (FAISS would be a good choice), returns nearest neighbors.
maaquib commented 2 years ago

@samils7 Thanks for the response and the details about your workflow details @VikasNeoito Please reopen if you need any help in additiona to @samils7 suggestion