Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

add image embedding normalization

Abhinav876b63973b64
diff --git a/src/services/clipService.ts b/src/services/clipService.ts
index 24e241bd62..26d8f7fde8 100644
--- a/src/services/clipService.ts
+++ b/src/services/clipService.ts
@@ -265,8 +265,16 @@ export async function computeONNXImageEmbedding(
input: new ort.Tensor('float32', rgbData, [1, 3, 224, 224]),
};
const results = await imageSession.run(feeds);
- const embedVec = results['output'].data; // Float32Array
- return embedVec;
+ const imageEmbedding = results['output'].data; // Float32Array
+ let imageNormalization = 0;
+ for (let index = 0; index < imageEmbedding.length; index++) {
+ imageNormalization += imageEmbedding[index] * imageEmbedding[index];
+ }
+ for (let index = 0; index < imageEmbedding.length; index++) {
+ imageEmbedding[index] =
+ imageEmbedding[index] / Math.sqrt(imageNormalization);
+ }
+ return imageEmbedding;
} catch (err) {
logErrorSentry(err, 'Error in computeImageEmbedding');
throw err;