Back to paper library
arXiv 2023VISAPP 2024Retail visionPaper notes

RetailKLIP

New Stock, No Retraining

Original paper

RetailKLIP : Finetuning OpenCLIP backbone using metric learning on a single GPU for Zero-shot retail product image classification

Paper authors

Muktabh Mayank Srivastava

Publication
VISAPP 2024Conference
First submitted to arXiv
arXiv:2312.10282
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{retailproductretailklip2023,
  title = {{RetailKLIP : Finetuning OpenCLIP backbone using metric learning on a single GPU for Zero-shot retail product image classification}},
  author = {Muktabh Mayank Srivastava},
  year = {2023},
  eprint = {2312.10282},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.10282}
}
On this page

A supermarket's product list changes every month. A new flavor launches, the packaging gets redesigned, a "buy one, get one free" sticker goes on, and to a classification model each of these is a new class.

The traditional approach is to retrain the model whenever a batch of new products arrives, or at least retrain the last layer. That brings two headaches. One is cost: a model with thousands of classes has to run a few epochs even if all you're adding is two photos of a new product. The other is the blind spot: until the new model finishes training, the system can't recognize the new products at all.

This paper comes from ParallelDots, an Indian retail AI company, and has a single author. The author's idea is to swap classification for nearest-neighbor search. First, tune a CLIP image encoder to suit products; after that, each new product needs only one photo and a stored embedding vector to go live.

Problem Definition

The author calls it "zero-shot classification". Zero-shot here means no training at all on the new dataset: one reference image per product serves as the gallery, and nearest neighbor decides which product a test image shows. Strictly speaking, this is closer to a one-shot setting.

The author sets a self-imposed limit. Everything has to train on a single GPU, and the methods compared against must also be models a single GPU can train.

Why CLIP? CLIP's image encoder was trained on billions of image-text pairs, and its embeddings are useful in their own right; using them directly for nearest neighbor is a decent starting point on many datasets. But it was trained on web images, so for products on a shelf it's best fine-tuned a bit further. And CLIP is notoriously hard to fine-tune; do it badly and you lose the abilities it started with.

Solution

Flowchart drawn for this note, in two stages. Stage 1 is fine-tuning, done once: the OpenCLIP image encoder (ViT-L/14, LAION-2B pretrained, no text encoder) is fine-tuned on the in-house RP6K (6,500 products, over a million images, long-tailed, with the largest classes near 4,000 images), using an ArcFace loss and the AdamW optimizer, plus block-wise learning-rate decay ×0.7 and class resampling. Stage 2 is zero-shot classification, with no training on new datasets: take only 1 image per product, add a few augmentations and store the embeddings as the gallery; the query image is embedded by RetailKLIP; nearest neighbor (k = 1) finds the closest product embedding, which gives the predicted label.
Drawn for this note from Section 4 of the paper.

What It Is Fine-tuned On

Fine-tuning uses RP6K, the company's in-house dataset of 6,500 products and over a million images, which is not public. The distribution is long-tailed: popular products have nearly 4,000 images, while many have fewer than 10. The author specifically checked that none of the products in Grozi-120 and CAPG-GP, the datasets used later for evaluation, are in RP6K.

ArcFace Instead of a Classification Loss

The point of fine-tuning is to get embeddings that suit nearest neighbor, so instead of the usual softmax classification loss, the author uses ArcFace, which is common in face recognition.

ArcFace normalizes every embedding and every class center onto the unit sphere, measures similarity by angle, and adds a fixed angular margin to the angle of the correct class. The model has to pack same-class embeddings tighter than "just barely separable", and the space it learns works better on classes it has never seen. Face recognition is a lot like this case: the people seen in training and the people to recognize after deployment are usually not the same group.

The author also notes that on long-tailed data, plain ArcFace already beats softmax with data-balancing tricks, which is another reason for picking it.

Fine-tuning CLIP Without Breaking It

To avoid ruining CLIP, the author borrows two techniques from earlier work.

One is the AdamW optimizer, recommended by a paper that studied how to fine-tune vision models.

The other is a learning rate that shrinks with depth. The usual approach is layer-wise decay: the top layer gets the largest learning rate, and each layer further down is multiplied by a fixed ratio. The author switches the unit to Transformer blocks. The top block's learning rate is 2×10−42 \times 10^{-4}, and each block further down is multiplied by 0.7. By blocks, the paper means the Transformer layers and other layers that OpenCLIP's code labels as blocks.

ViT-L has 24 Transformer blocks. Assuming those 24 are the blocks, let's work out what's left at the bottom. The kk-th block from the top has a learning rate of 2×10−4×0.7k−12 \times 10^{-4} \times 0.7^{k-1}; at the 24th, 0.723≈2.7×10−40.7^{23} \approx 2.7 \times 10^{-4}, so the learning rate is about 5.5×10−85.5 \times 10^{-8}, more than 3,000 times smaller than at the top. In other words, the layers nearest the input barely move and keep the low-level features CLIP originally learned; the higher up, the more they get tuned.

Class Balancing

Last comes data balancing. The author splits it into two questions: breadth, how many classes training covers, and depth, how many images each class contributes. Breadth is set to the maximum, every class included. For depth, the author carves a validation set with the same number of images per class out of RP6K, tries several values and keeps the one with the highest accuracy. Classes with too few images are oversampled and those with too many undersampled, together with data augmentation.

How It's Used

The fine-tuned model is RetailKLIP. Given a new dataset, take one image per product from the training set, apply several augmentations, and feed them all through RetailKLIP to get a set of embeddings that represent the product. At test time, an image is assigned to whichever product its embedding is closest to.

When a new product goes on the shelf, you take one more photo, compute its embedding once and add it to the gallery; the model itself stays untouched.

Discussion

Bar chart drawn for this note comparing four methods' accuracy on two datasets; solid bars are CAPG-GP and outlined bars Grozi-120. ResNeXt-WSL, whole backbone fine-tuned: 84.1%, 60.4%. ResNeXt-WSL plus LCA and MaxEnt, whole backbone fine-tuned: 92.2%, 72.3%. Semi-supervised backbone plus a linear layer, only the last layer trained: 87.6%, 76.19%. RetailKLIP, zero-shot, no training: 88.6%, 82.8%. The horizontal axis starts at 50%.
Drawn for this note; numbers from Table 1 (CAPG-GP) and Table 2 (Grozi-120) of the paper.

The evaluation uses two one-shot datasets. Grozi-120 has 120 products, with studio product shots as reference images and photos taken in stores as test images; CAPG-GP has fine-grained products whose reference and test images come from similar environments.

On Grozi-120, RetailKLIP's 82.8% is the best of the four methods, 6.6 points above the method that trains only the last layer and 10 to 22 points above the fully fine-tuned ResNeXt models. Studio reference images against in-store test images is a cross-domain setting, and that is where CLIP pretraining shows its advantage most clearly.

On CAPG-GP, RetailKLIP scores 88.6%, 3.6 points below full fine-tuning with the LCA layer and MaxEnt loss, but without any training on this dataset.

On RP2K, with all 2,388 classes together and a single reference image per class, accuracy is 87.7%. The author compares this with the original RP2K paper, saying that paper fine-tuned one category at a time, reaching 95% on some categories and under 90% on harder ones, and that "due to language barrier" the team couldn't separate the data by category and had to test everything combined.

In fact, the RP2K paper already classified all 2,388 classes together and only broke the results down by its seven categories when reporting them; ResNet-34's overall accuracy was 95.18%, using the full training set at an average of 160 images per class. So the two settings differ in the number of reference images, one against more than a hundred, while the range of classes is the same. Seen that way, 87.7% from a single reference image is actually a pretty good result.

What's Missing

The paper is only five pages long and leaves a few gaps.

The most obvious is a missing baseline, OpenCLIP without fine-tuning. The author says in the introduction that using CLIP embeddings directly for nearest neighbor is already a very good starting point. How much this round of fine-tuning on RP6K actually adds is exactly the number readers most want to see, and the paper doesn't report it.

Second, ablations. For ArcFace, block-wise learning-rate decay and class balancing alike, the paper only says in prose that "we find" one choice works better, with no numbers attached.

Third, reproducibility. RP6K, the fine-tuning data, is in-house and unreleased, and the paper provides no code or model weights either. Of the other three baselines in the tables, two cite the author's own earlier papers.

Conclusion

RetailKLIP offers a very practical engineering recipe. Fine-tune CLIP's image encoder once with ArcFace on a large in-house product dataset; after that, whatever new product dataset comes along, one reference image and one stored embedding per product are enough to classify directly by nearest neighbor, and new products go on the shelf without retraining.

On Grozi-120, with studio reference images and in-store test images, it beats every method that needs training; on the other datasets it isn't far behind full fine-tuning.

But that's as much as the paper can tell us. How much the fine-tuning itself contributes and which trick matters most come with no numbers, and neither the data nor the model is available. If you want to try it in your own store, what this paper gives you is a recipe: CLIP ViT-L, ArcFace, AdamW, block-wise decay of 0.7, class balancing with breadth maxed out. How much of each ingredient to use is something you'll have to work out slowly on your own products.