|
@@ -560,10 +560,10 @@ class FaceClusteringService {
|
|
|
for (int j = i - 1; j >= 0; j--) {
|
|
|
late double distance;
|
|
|
if (sortedFaceInfos[i].vEmbedding != null) {
|
|
|
- distance = 1.0 -
|
|
|
- sortedFaceInfos[i]
|
|
|
- .vEmbedding!
|
|
|
- .dot(sortedFaceInfos[j].vEmbedding!);
|
|
|
+ distance = cosineDistanceSIMD(
|
|
|
+ sortedFaceInfos[i].vEmbedding!,
|
|
|
+ sortedFaceInfos[j].vEmbedding!,
|
|
|
+ );
|
|
|
} else {
|
|
|
distance = cosineDistForNormVectors(
|
|
|
sortedFaceInfos[i].embedding!,
|
|
@@ -804,8 +804,10 @@ class FaceClusteringService {
|
|
|
double closestDistance = double.infinity;
|
|
|
for (int j = 0; j < totalFaces; j++) {
|
|
|
if (i == j) continue;
|
|
|
- final double distance =
|
|
|
- 1.0 - faceInfos[i].vEmbedding!.dot(faceInfos[j].vEmbedding!);
|
|
|
+ final double distance = cosineDistanceSIMD(
|
|
|
+ faceInfos[i].vEmbedding!,
|
|
|
+ faceInfos[j].vEmbedding!,
|
|
|
+ );
|
|
|
if (distance < closestDistance) {
|
|
|
closestDistance = distance;
|
|
|
closestIdx = j;
|
|
@@ -855,10 +857,10 @@ class FaceClusteringService {
|
|
|
for (int i = 0; i < clusterIds.length; i++) {
|
|
|
for (int j = 0; j < clusterIds.length; j++) {
|
|
|
if (i == j) continue;
|
|
|
- final double newDistance = 1.0 -
|
|
|
- clusterIdToMeanEmbeddingAndWeight[clusterIds[i]]!.$1.dot(
|
|
|
- clusterIdToMeanEmbeddingAndWeight[clusterIds[j]]!.$1,
|
|
|
- );
|
|
|
+ final double newDistance = cosineDistanceSIMD(
|
|
|
+ clusterIdToMeanEmbeddingAndWeight[clusterIds[i]]!.$1,
|
|
|
+ clusterIdToMeanEmbeddingAndWeight[clusterIds[j]]!.$1,
|
|
|
+ );
|
|
|
if (newDistance < distance) {
|
|
|
distance = newDistance;
|
|
|
clusterIDsToMerge = (clusterIds[i], clusterIds[j]);
|