Metric learning recognizes products by similarity

A metric learning model turns an image into an embedding, a vector that lies close to the embeddings of the same item and far from others. In Supervisely, models from the winning solution of the Google Landmark Recognition 2020 challenge match objects on store shelves to a reference catalog, so annotators tag products from a short list of suggestions.

Poster of the Metric Learning Labeling Tool: a bag of chips on a shelf matched to its catalog item with a similarity score
Labels
  • Item tags on objects, cropped to their bounding boxes
Apps
Serve, Apply
Source
Paper, GitHub

Apps in the Supervisely Ecosystem

Every model in Supervisely comes as a Supervisely App: a module from the Ecosystem that plugs into the platform and runs on your own GPU, with no code to install. A Serve App puts the model behind the labeling tools, and where the model can be trained, a Train App fits it to your labeled project. All Apps work on the same projects, so you add a model, update it or swap it for another without changing anything else.

A landmark recognizer reused for products

The apps build on the 1st-place solution of the 2020 Google Landmark Recognition competition on Kaggle, described by Christof Henkel and Philipp Singer in "Supporting large-scale image recognition with out-of-domain samples". Convolutional networks trained with an additive angular margin (ArcFace) loss embed images in a high-dimensional space, and an image is classified by its visual similarity to labeled ones. The paper then re-ranks predictions and filters noise with the help of out-of-domain images.

Every checkpoint of Serve Metric Learning uses the same setup from the repository's configs: an SE-ResNeXt-101 backbone, GeM pooling, 512-dimensional embeddings and an ArcFace head, on 448 × 448 inputs. Because recognition is a nearest-neighbor search over embeddings, a new item needs reference images in the database, not a retrained model.

Five pretrained models

ModelClassesWeights file
retail [medium]12,075r2pk_and_10k.ckpt
retail [small]2,384r2pk.ckpt
retail [nano]83snacks_v1.ckpt
landmarks [medium]10,752landmarks.ckpt
pictures [nano]83pictures_v1.ckpt

The retail checkpoints are named after the RP2K and Products-10K retail datasets, and retail [medium] is the default. The app deploys on a GPU or a CPU, and it also loads a custom checkpoint from Team Files. Other apps call it through its API: it takes an image URL and a bounding box and returns the embedding of the crop.

From a catalog to tagged shelves

The Retail Collection groups the apps into one workflow. All it needs is a CSV catalog with image_url and item_id columns and an agent with a GPU.

  1. Turn the CSV into an images project with CSV Products Catalog to Images Project. This is the reference catalog.
  2. Run Serve Metric Learning: choose a model and the device.
  3. Run Embeddings Calculator from the catalog project's context menu and select the served session. Every image must carry its item tag. Each object is cropped to its bounding box and embedded, a whole image when it has no objects, and the results go to Team Files.
  4. Run AI Recommendations on the project, select the checkpoint the embeddings were computed with and load them. It stays running and answers requests with the closest catalog items and their cosine similarity.
  5. Open the images to label in the image labeling toolbox and run Metric Learning Labeling Tool from its Apps tab.

Tagging products with suggestions

Products on the shelf are labeled as objects first. For the selected object, the labeling tool shows the top N predicted items from the reference database, with their scores, and a click assigns the item tag. It moves between objects with Ctrl + ] and Ctrl + [ and zooms to each one.

  • Add to the reference database: an item tagged by hand can join the catalog, and AI Recommendations updates the database in memory, so the next shelf finds it.
  • Review mode: check the objects that already carry tags.
  • Copy mode: repeat the last tag on the next objects, for rows of the same product.
  • Catalog: browse the reference database when the right item is not among the suggestions.

This is model-assisted labeling for catalogs with thousands of items, where picking a tag from a full list is slow. The image tagging guide puts the tool next to the other tagging apps. The Grocery store shelves project in the Ecosystem has labeled and untagged images to try it on.

Limits and other options

There is no training app for these models in Supervisely. The repository trains them with src/train.py and a config file, outside the platform, and the result can be served as a custom checkpoint. The tool tags objects, so the shelf needs boxes or other shapes first; a detector such as YOLO trained on a single "product" class can draw them.

For a fixed list of classes learned from tags, train an image classification model with MMPretrain. To find images by a phrase rather than by an example, use CLIP.

Frequently asked questions.

What is metric learning in computer vision?

Training a model to map images to embeddings so that images of the same item lie close together and different items lie far apart. A new image is then recognized by its nearest neighbors in a reference database, rather than by a fixed set of output classes.

Can I add new products without retraining the model?

Yes. Tag a new item in Metric Learning Labeling Tool and add it to the reference database. AI Recommendations updates the database in memory, so the next matching object gets it as a suggestion.

Can I train the metric learning model in Supervisely?

Not in an app. The repository has a training script that runs with a config file outside Supervisely, and Serve Metric Learning loads the resulting checkpoint from Team Files.

What is ArcFace loss?

ArcFace, the additive angular margin loss, trains embeddings by adding a margin to the angle between an embedding and its class center, so items of one class cluster tightly and different classes stay apart. It was introduced for face recognition; the metric learning models in Supervisely put an ArcFace head on an SE-ResNeXt-101 backbone.

Train and serve models on your own data.

Label a project in a free account, train a model on it from the browser and deploy it on your own GPU. Or book a demo to run Supervisely on your servers.