This commit is contained in:
Neeraj Gupta
2024-08-16 17:50:44 +05:30
parent b6d5ebc5b4
commit b03b5806db
6 changed files with 23 additions and 39 deletions

View File

@@ -12,7 +12,6 @@ const isSideways = 'is_sideways';
const imageWidth = 'width';
const imageHeight = 'height';
const mlVersionColumn = 'ml_version';
const personIdColumn = 'person_id';
const clusterIDColumn = 'cluster_id';

View File

@@ -0,0 +1,9 @@
import 'package:nanoid/nanoid.dart';
const enteWhiteListedAlphabet =
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const clusterIDLength = 22;
String newClusterID() {
return "cluster_${customAlphabet(enteWhiteListedAlphabet, clusterIDLength)}";
}

View File

@@ -1,25 +0,0 @@
import "package:flutter/foundation.dart";
import 'package:nanoid/nanoid.dart';
const enteWhiteListedAlphabet =
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const clusterIDLength = 22;
class ClusterID {
static String generate() {
return "cluster_${customAlphabet(enteWhiteListedAlphabet, clusterIDLength)}";
}
// Validation method
static bool isValidClusterID(String value) {
if (value.length != (clusterIDLength + 8)) {
debugPrint("ClusterID length is not ${clusterIDLength + 8}: $value");
return false;
}
if (value.startsWith("cluster_")) {
debugPrint("ClusterID doesn't start with _cluster: $value");
return false;
}
return true;
}
}

View File

@@ -9,7 +9,7 @@ import "package:logging/logging.dart";
import "package:ml_linalg/dtype.dart";
import "package:ml_linalg/vector.dart";
import "package:photos/generated/protos/ente/common/vector.pb.dart";
import "package:photos/models/nanoids/cluster_id.dart";
import "package:photos/models/base/id.dart";
import "package:photos/services/machine_learning/face_ml/face_clustering/face_db_info_for_clustering.dart";
import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart";
import "package:photos/services/machine_learning/ml_result.dart";
@@ -491,11 +491,11 @@ ClusteringResult _runLinearClustering(Map args) {
"[ClusterIsolate] ${DateTime.now()} Processing $totalFaces faces in total in this round ${offset != null ? "on top of ${offset + facesWithClusterID.length} earlier processed faces" : ""}",
);
// set current epoch time as clusterID
String clusterID = ClusterID.generate();
String clusterID = newClusterID();
if (facesWithClusterID.isEmpty) {
// assign a clusterID to the first face
sortedFaceInfos[0].clusterId = clusterID;
clusterID = ClusterID.generate();
clusterID = newClusterID();
}
final stopwatchClustering = Stopwatch()..start();
for (int i = 1; i < totalFaces; i++) {
@@ -539,12 +539,13 @@ ClusteringResult _runLinearClustering(Map args) {
log(
" [ClusterIsolate] [WARNING] ${DateTime.now()} Found new cluster $clusterID",
);
clusterID = ClusterID.generate();
clusterID = newClusterID();
sortedFaceInfos[closestIdx].clusterId = clusterID;
}
sortedFaceInfos[i].clusterId = sortedFaceInfos[closestIdx].clusterId;
} else {
clusterID = ClusterID.generate();
clusterID = newClusterID();
;
sortedFaceInfos[i].clusterId = clusterID;
}
}
@@ -634,7 +635,7 @@ ClusteringResult _runCompleteClustering(Map args) {
"[CompleteClustering] ${DateTime.now()} Processing $totalFaces faces in one single round of complete clustering",
);
String clusterID = ClusterID.generate();
String clusterID = newClusterID();
// Start actual clustering
final Map<String, String> newFaceIdToCluster = {};
@@ -658,12 +659,12 @@ ClusteringResult _runCompleteClustering(Map args) {
if (closestDistance < distanceThreshold) {
if (faceInfos[closestIdx].clusterId == null) {
clusterID = ClusterID.generate();
clusterID = newClusterID();
faceInfos[closestIdx].clusterId = clusterID;
}
faceInfos[i].clusterId = faceInfos[closestIdx].clusterId!;
} else {
clusterID = ClusterID.generate();
clusterID = newClusterID();
faceInfos[i].clusterId = clusterID;
}
}

View File

@@ -6,10 +6,10 @@ import "package:flutter/foundation.dart" show kDebugMode;
import "package:flutter/material.dart";
import "package:photos/db/ml/db.dart";
import "package:photos/extensions/stop_watch.dart";
import "package:photos/models/base/id.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/ml/face/face.dart";
import "package:photos/models/ml/face/person.dart";
import "package:photos/models/nanoids/cluster_id.dart";
import "package:photos/services/machine_learning/face_ml/face_detection/detection.dart";
import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";
import "package:photos/services/search_service.dart";
@@ -99,9 +99,9 @@ class _FaceWidgetState extends State<FaceWidget> {
}
// Create new clusterID for the faceID and update DB to assign the faceID to the new clusterID
final String newClusterID = ClusterID.generate();
final String clusterID = newClusterID();
await MLDataDB.instance.updateFaceIdToClusterId(
{widget.face.faceID: newClusterID},
{widget.face.faceID: clusterID},
);
// Push page for the new cluster
@@ -109,7 +109,7 @@ class _FaceWidgetState extends State<FaceWidget> {
MaterialPageRoute(
builder: (context) => ClusterPage(
[widget.file],
clusterID: newClusterID,
clusterID: clusterID,
),
),
);

View File

@@ -124,9 +124,9 @@ dependencies:
git: "https://github.com/ente-io/motionphoto.git"
move_to_background: ^1.0.2
nanoid: ^1.0.0
native_video_player: ^1.3.1
onnx_dart:
path: plugins/onnx_dart
native_video_player: ^1.3.1
onnxruntime:
git:
url: https://github.com/ente-io/onnxruntime.git