From f3006929295aefc263b30483116d92c6342a756e Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Fri, 22 Dec 2023 21:44:54 +0530 Subject: [PATCH] Added cosine similarity method to iOS MPPImagEmbedder --- .../image_embedder/sources/MPPImageEmbedder.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mediapipe/tasks/ios/vision/image_embedder/sources/MPPImageEmbedder.h b/mediapipe/tasks/ios/vision/image_embedder/sources/MPPImageEmbedder.h index b3cb795bf..df518210a 100644 --- a/mediapipe/tasks/ios/vision/image_embedder/sources/MPPImageEmbedder.h +++ b/mediapipe/tasks/ios/vision/image_embedder/sources/MPPImageEmbedder.h @@ -245,6 +245,24 @@ NS_SWIFT_NAME(ImageEmbedder) - (instancetype)init NS_UNAVAILABLE; +/** + * Utility function to compute[cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) + * between two `MPPEmbedding` objects. + * + * @param embedding1 One of the two `MPPEmbedding`s between whom cosine similarity is to be + * computed. + * @param embedding2 One of the two `MPPEmbedding`s between whom cosine similarity is to be + * computed. + * @param error An optional error parameter populated when there is an error in calculating cosine + * similarity between two embeddings. + * + * @return An `NSNumber` which holds the cosine similarity of type `double`. + */ ++ (nullable NSNumber *)cosineSimilarityBetweenEmbedding1:(MPPEmbedding *)embedding1 + andEmbedding2:(MPPEmbedding *)embedding2 + error:(NSError **)error + NS_SWIFT_NAME(cosineSimilarity(embedding1:embedding2:)); + + (instancetype)new NS_UNAVAILABLE; @end