Metric Learning for Anomaly Detection
Blog post from Qdrant
Anomaly detection, a complex task due to data scarcity and frequent changes in anomalies, can benefit from metric learning, as demonstrated by Agrivero.ai's approach to evaluating coffee bean quality with AI. By utilizing metric learning, the company encoded images into vector space and employed K-nearest neighbors (KNN) classification to label data based on learned similarities, which allows for leveraging unlabeled data and adjusting metrics like precision and recall without retraining. Initially, a Resnet18-like autoencoder was pretrained to represent the target domain, followed by finetuning with metric learning using a small sample size and triplet loss, which proved efficient despite some overfitting challenges. The results showed that metric learning, using only 0.66% of the labeled data needed for traditional supervised classification, achieved comparable performance, highlighting significant savings in time and resources. This method suggests potential improvements through larger unlabeled datasets, high-quality labels for fewer images, hyperparameter optimization, and the use of vector search engines for production deployment.