Skip to content

armgit / ente

Public Imported from GitHub
0

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

rename

Neeraj Gupta2cf8bd14f9d7
diff --git a/mobile/lib/core/configuration.dart b/mobile/lib/core/configuration.dart
index 9fe284c583..16a65d497f 100644
--- a/mobile/lib/core/configuration.dart
+++ b/mobile/lib/core/configuration.dart
@@ -205,7 +205,7 @@ class Configuration {
await FilesDB.instance.clearTable();
await CollectionsDB.instance.clearTable();
await MemoriesDB.instance.clearTable();
- await FaceMLDataDB.instance.clearTable();
+ await MLDataDB.instance.clearTable();
await UploadLocksDB.instance.clearTable();
await IgnoredFilesService.instance.reset();
diff --git a/mobile/lib/db/ml/db.dart b/mobile/lib/db/ml/db.dart
index 89cab01b81..8276ec0a25 100644
--- a/mobile/lib/db/ml/db.dart
+++ b/mobile/lib/db/ml/db.dart
@@ -17,7 +17,7 @@ import "package:photos/services/machine_learning/ml_result.dart";
import "package:photos/utils/ml_util.dart";
import 'package:sqlite_async/sqlite_async.dart';
-/// Stores all data for the FacesML-related features. The database can be accessed by `FaceMLDataDB.instance.database`.
+/// Stores all data for the FacesML-related features. The database can be accessed by `MLDataDB.instance.database`.
///
/// This includes:
/// [facesTable] - Stores all the detected faces and its embeddings in the images.
@@ -25,16 +25,16 @@ import 'package:sqlite_async/sqlite_async.dart';
/// [clusterPersonTable] - Stores all the clusters that are mapped to a certain person.
/// [clusterSummaryTable] - Stores a summary of each cluster, containg the mean embedding and the number of faces in the cluster.
/// [notPersonFeedback] - Stores the clusters that are confirmed not to belong to a certain person by the user
-class FaceMLDataDB {
- static final Logger _logger = Logger("FaceMLDataDB");
+class MLDataDB {
+ static final Logger _logger = Logger("MLDataDB");
static const _databaseName = "ente.face_ml_db_v3.db";
// static const _databaseVersion = 1;
- FaceMLDataDB._privateConstructor();
+ MLDataDB._privateConstructor();
- static final FaceMLDataDB instance = FaceMLDataDB._privateConstructor();
+ static final MLDataDB instance = MLDataDB._privateConstructor();
static final _migrationScripts = [
createFacesTable,
@@ -62,10 +62,10 @@ class FaceMLDataDB {
final asyncDBConnection =
SqliteDatabase(path: databaseDirectory, maxReaders: 2);
final stopwatch = Stopwatch()..start();
- _logger.info("FaceMLDataDB: Starting migration");
+ _logger.info("MLDataDB: Starting migration");
await _migrate(asyncDBConnection);
_logger.info(
- "FaceMLDataDB Migration took ${stopwatch.elapsedMilliseconds} ms",
+ "MLDataDB Migration took ${stopwatch.elapsedMilliseconds} ms",
);
stopwatch.stop();
@@ -355,7 +355,8 @@ class FaceMLDataDB {
if (faces != null) {
for (final face in faces) {
if (faceMaps.any(
- (element) => (element[faceIDColumn] as String) == face.faceID,)) {
+ (element) => (element[faceIDColumn] as String) == face.faceID,
+ )) {
return face;
}
}
diff --git a/mobile/lib/db/ml/embeddings_db.dart b/mobile/lib/db/ml/embeddings_db.dart
index 8d59e8504b..9c362b3d66 100644
--- a/mobile/lib/db/ml/embeddings_db.dart
+++ b/mobile/lib/db/ml/embeddings_db.dart
@@ -7,18 +7,18 @@ import "package:photos/db/ml/db_fields.dart";
import "package:photos/events/embedding_updated_event.dart";
import "package:photos/models/ml/clip.dart";
-extension EmbeddingsDB on FaceMLDataDB {
+extension EmbeddingsDB on MLDataDB {
static const databaseName = "ente.embeddings.db";
Future<List<ClipEmbedding>> getAll() async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
final results = await db.getAll('SELECT * FROM $clipTable');
return _convertToEmbeddings(results);
}
// Get indexed FileIDs
Future<Map<int, int>> clipIndexedFileWithVersion() async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
final maps = await db
.getAll('SELECT $fileIDColumn , $mlVersionColumn FROM $clipTable');
final Map<int, int> result = {};
@@ -29,7 +29,7 @@ extension EmbeddingsDB on FaceMLDataDB {
}
Future<int> getClipIndexedFileCount() async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
const String query =
'SELECT COUNT(DISTINCT $fileIDColumn) as count FROM $clipTable';
final List<Map<String, dynamic>> maps = await db.getAll(query);
@@ -37,7 +37,7 @@ extension EmbeddingsDB on FaceMLDataDB {
}
Future<void> put(ClipEmbedding embedding) async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
await db.execute(
'INSERT OR REPLACE INTO $clipTable ($fileIDColumn, $embeddingColumn, $mlVersionColumn) VALUES (?, ?, ?)',
_getRowFromEmbedding(embedding),
@@ -46,7 +46,7 @@ extension EmbeddingsDB on FaceMLDataDB {
}
Future<void> putMany(List<ClipEmbedding> embeddings) async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
final inputs = embeddings.map((e) => _getRowFromEmbedding(e)).toList();
await db.executeBatch(
'INSERT OR REPLACE INTO $clipTable ($fileIDColumn, $embeddingColumn, $mlVersionColumn) values(?, ?, ?)',
@@ -56,7 +56,7 @@ extension EmbeddingsDB on FaceMLDataDB {
}
Future<void> deleteEmbeddings(List<int> fileIDs) async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
await db.execute(
'DELETE FROM $clipTable WHERE $fileIDColumn IN (${fileIDs.join(", ")})',
);
@@ -64,7 +64,7 @@ extension EmbeddingsDB on FaceMLDataDB {
}
Future<void> deleteClipIndexes() async {
- final db = await FaceMLDataDB.instance.asyncDB;
+ final db = await MLDataDB.instance.asyncDB;
await db.execute('DELETE FROM $clipTable');
Bus.instance.fire(EmbeddingUpdatedEvent());
}
diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart
index 0c2fe17436..896505b298 100644
--- a/mobile/lib/main.dart
+++ b/mobile/lib/main.dart
@@ -311,7 +311,7 @@ Future<void> _init(bool isBackground, {String via = ''}) async {
}
PersonService.init(
EntityService.instance,
- FaceMLDataDB.instance,
+ MLDataDB.instance,
preferences,
);
diff --git a/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart b/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart
index e51931e254..f2a6f03e31 100644
--- a/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart
+++ b/mobile/lib/services/machine_learning/face_ml/face_recognition_service.dart
@@ -143,8 +143,8 @@ class FaceRecognitionService {
}
}
}
- await FaceMLDataDB.instance.bulkInsertFaces(faces);
- await FaceMLDataDB.instance.putMany(clipEmbeddings);
+ await MLDataDB.instance.bulkInsertFaces(faces);
+ await MLDataDB.instance.putMany(clipEmbeddings);
}
// Yield any remaining instructions
if (batchToYield.isNotEmpty) {
diff --git a/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart b/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
index f02110baca..a144fc5fcc 100644
--- a/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
+++ b/mobile/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart
@@ -78,11 +78,11 @@ class ClusterFeedbackService {
// Get the files for the suggestions
final suggestionClusterIDs = foundSuggestions.map((e) => e.$1).toSet();
final Map<int, Set<String>> fileIdToClusterID =
- await FaceMLDataDB.instance.getFileIdToClusterIDSetForCluster(
+ await MLDataDB.instance.getFileIdToClusterIDSetForCluster(
suggestionClusterIDs,
);
final clusterIdToFaceIDs =
- await FaceMLDataDB.instance.getClusterToFaceIDs(suggestionClusterIDs);
+ await MLDataDB.instance.getClusterToFaceIDs(suggestionClusterIDs);
final Map<String, List<EnteFile>> clusterIDToFiles = {};
final allFiles = await SearchService.instance.getAllFiles();
for (final f in allFiles) {
@@ -141,7 +141,7 @@ class ClusterFeedbackService {
try {
_logger.info('removeFilesFromPerson called');
// Get the relevant faces to be removed
- final faceIDs = await FaceMLDataDB.instance
+ final faceIDs = await MLDataDB.instance
.getFaceIDsForPerson(p.remoteID)
.then((iterable) => iterable.toList());
faceIDs.retainWhere((faceID) {
@@ -149,7 +149,7 @@ class ClusterFeedbackService {
return files.any((file) => file.uploadedFileID == fileID);
});
final embeddings =
- await FaceMLDataDB.instance.getFaceEmbeddingMapForFaces(faceIDs);
+ await MLDataDB.instance.getFaceEmbeddingMapForFaces(faceIDs);
if (faceIDs.isEmpty || embeddings.isEmpty) {
_logger.severe(
@@ -175,8 +175,8 @@ class ClusterFeedbackService {
final newFaceIdToClusterID = clusterResult.newFaceIdToCluster;
// Update the deleted faces
- await FaceMLDataDB.instance.forceUpdateClusterIds(newFaceIdToClusterID);
- await FaceMLDataDB.instance
+ await MLDataDB.instance.forceUpdateClusterIds(newFaceIdToClusterID);
+ await MLDataDB.instance
.clusterSummaryUpdate(clusterResult.newClusterSummaries);
// Make sure the deleted faces don't get suggested in the future
@@ -184,7 +184,7 @@ class ClusterFeedbackService {
for (final clusterId in newFaceIdToClusterID.values.toSet()) {
notClusterIdToPersonId[clusterId] = p.remoteID;
}
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.bulkCaptureNotPersonFeedback(notClusterIdToPersonId);
// Update remote so new sync does not undo this change
@@ -207,7 +207,7 @@ class ClusterFeedbackService {
_logger.info('removeFilesFromCluster called');
try {
// Get the relevant faces to be removed
- final faceIDs = await FaceMLDataDB.instance
+ final faceIDs = await MLDataDB.instance
.getFaceIDsForCluster(clusterID)
.then((iterable) => iterable.toList());
faceIDs.retainWhere((faceID) {
@@ -215,7 +215,7 @@ class ClusterFeedbackService {
return files.any((file) => file.uploadedFileID == fileID);
});
final embeddings =
- await FaceMLDataDB.instance.getFaceEmbeddingMapForFaces(faceIDs);
+ await MLDataDB.instance.getFaceEmbeddingMapForFaces(faceIDs);
if (faceIDs.isEmpty || embeddings.isEmpty) {
_logger.severe(
@@ -241,8 +241,8 @@ class ClusterFeedbackService {
final newFaceIdToClusterID = clusterResult.newFaceIdToCluster;
// Update the deleted faces
- await FaceMLDataDB.instance.forceUpdateClusterIds(newFaceIdToClusterID);
- await FaceMLDataDB.instance
+ await MLDataDB.instance.forceUpdateClusterIds(newFaceIdToClusterID);
+ await MLDataDB.instance
.clusterSummaryUpdate(clusterResult.newClusterSummaries);
Bus.instance.fire(
@@ -265,7 +265,7 @@ class ClusterFeedbackService {
for (final faceID in faceIDs) {
faceIDToClusterID[faceID] = clusterID;
}
- await FaceMLDataDB.instance.forceUpdateClusterIds(faceIDToClusterID);
+ await MLDataDB.instance.forceUpdateClusterIds(faceIDToClusterID);
Bus.instance.fire(PeopleChangedEvent());
return;
}
@@ -274,7 +274,7 @@ class ClusterFeedbackService {
PersonEntity p, {
required String personClusterID,
}) async {
- final faceMlDb = FaceMLDataDB.instance;
+ final faceMlDb = MLDataDB.instance;
final faceIDs = await faceMlDb.getFaceIDsForCluster(personClusterID);
final ignoredClusters = await faceMlDb.getPersonIgnoredClusters(p.remoteID);
if (faceIDs.length < 2 * kMinimumClusterSizeSearchResult) {
@@ -323,7 +323,7 @@ class ClusterFeedbackService {
for (final suggestion in suggestions) {
final clusterID = suggestion.$1;
- await FaceMLDataDB.instance.assignClusterToPerson(
+ await MLDataDB.instance.assignClusterToPerson(
personID: p.remoteID,
clusterID: clusterID,
);
@@ -341,7 +341,7 @@ class ClusterFeedbackService {
}
Future<List<(String, int)>> checkForMixedClusters() async {
- final faceMlDb = FaceMLDataDB.instance;
+ final faceMlDb = MLDataDB.instance;
final allClusterToFaceCount = await faceMlDb.clusterIdToFaceCount();
final clustersToInspect = <String>[];
for (final clusterID in allClusterToFaceCount.keys) {
@@ -439,7 +439,7 @@ class ClusterFeedbackService {
_logger.info(
'breakUpCluster called for cluster $clusterID with dbscan $useDbscan',
);
- final faceMlDb = FaceMLDataDB.instance;
+ final faceMlDb = MLDataDB.instance;
final faceIDs = await faceMlDb.getFaceIDsForCluster(clusterID);
final originalFaceIDsSet = faceIDs.toSet();
@@ -502,18 +502,18 @@ class ClusterFeedbackService {
}) async {
final w = (kDebugMode ? EnteWatch('getSuggestions') : null)?..start();
// Get all the cluster data
- final faceMlDb = FaceMLDataDB.instance;
+ final faceMlDb = MLDataDB.instance;
final allClusterIdsToCountMap = await faceMlDb.clusterIdToFaceCount();
final ignoredClusters = await faceMlDb.getPersonIgnoredClusters(p.remoteID);
final personClusters = await faceMlDb.getPersonClusterIDs(p.remoteID);
final personFaceIDs =
- await FaceMLDataDB.instance.getFaceIDsForPerson(p.remoteID);
+ await MLDataDB.instance.getFaceIDsForPerson(p.remoteID);
final personFileIDs = personFaceIDs.map(getFileIdFromFaceId).toSet();
w?.log(
'${p.data.name} has ${personClusters.length} existing clusters, getting all database data done',
);
final allClusterIdToFaceIDs =
- await FaceMLDataDB.instance.getAllClusterIdToFaceIDs();
+ await MLDataDB.instance.getAllClusterIdToFaceIDs();
w?.log('getAllClusterIdToFaceIDs done');
// First only do a simple check on the big clusters, if the person does not have small clusters yet
@@ -552,7 +552,7 @@ class ClusterFeedbackService {
final overlap = personFileIDs.intersection(suggestionSet);
if (overlap.isNotEmpty &&
((overlap.length / suggestionSet.length) > 0.5)) {
- await FaceMLDataDB.instance.captureNotPersonFeedback(
+ await MLDataDB.instance.captureNotPersonFeedback(
personID: p.remoteID,
clusterID: suggestion.$1,
);
@@ -599,7 +599,7 @@ class ClusterFeedbackService {
final List<Uint8List> personEmbeddingsProto = [];
for (final clusterID in personClusters) {
final Iterable<Uint8List> embeddings =
- await FaceMLDataDB.instance.getFaceEmbeddingsForCluster(clusterID);
+ await MLDataDB.instance.getFaceEmbeddingsForCluster(clusterID);
personEmbeddingsProto.addAll(embeddings);
}
final List<Uint8List> sampledEmbeddingsProto =
@@ -622,7 +622,7 @@ class ClusterFeedbackService {
double minMedianDistance = maxMedianDistance;
for (final otherClusterId in otherClusterIdsCandidates) {
final Iterable<Uint8List> otherEmbeddingsProto =
- await FaceMLDataDB.instance.getFaceEmbeddingsForCluster(
+ await MLDataDB.instance.getFaceEmbeddingsForCluster(
otherClusterId,
);
final sampledOtherEmbeddingsProto = _randomSampleWithoutReplacement(
@@ -698,7 +698,7 @@ class ClusterFeedbackService {
}) async {
final w = (kDebugMode ? EnteWatch('_getUpdateClusterAvg') : null)?..start();
final startTime = DateTime.now();
- final faceMlDb = FaceMLDataDB.instance;
+ final faceMlDb = MLDataDB.instance;
_logger.info(
'start getUpdateClusterAvg for ${allClusterIdsToCountMap.length} clusters, minClusterSize $minClusterSize, maxClusterInCurrentRun $maxClusterInCurrentRun',
);
@@ -775,8 +775,7 @@ class ClusterFeedbackService {
}
final Map<String, Iterable<Uint8List>> clusterEmbeddings =
- await FaceMLDataDB.instance
- .getFaceEmbeddingsForClusters(clusterIdsToRead);
+ await MLDataDB.instance.getFaceEmbeddingsForClusters(clusterIdsToRead);
w?.logAndReset(
'read $currentPendingRead embeddings for ${clusterEmbeddings.length} clusters',
@@ -887,7 +886,7 @@ class ClusterFeedbackService {
}
}
final startTime = DateTime.now();
- final faceMlDb = FaceMLDataDB.instance;
+ final faceMlDb = MLDataDB.instance;
// Get the cluster averages for the person's clusters and the suggestions' clusters
final personClusters = await faceMlDb.getPersonClusterIDs(person.remoteID);
@@ -993,7 +992,7 @@ class ClusterFeedbackService {
// Logging the cluster summary for the cluster
if (logClusterSummary) {
- final summaryMap = await FaceMLDataDB.instance.getClusterToClusterSummary(
+ final summaryMap = await MLDataDB.instance.getClusterToClusterSummary(
[clusterID, biggestClusterID],
);
final summary = summaryMap[clusterID];
@@ -1039,8 +1038,7 @@ class ClusterFeedbackService {
// Median distance
const sampleSize = 100;
- final Iterable<Uint8List> biggestEmbeddings = await FaceMLDataDB
- .instance
+ final Iterable<Uint8List> biggestEmbeddings = await MLDataDB.instance
.getFaceEmbeddingsForCluster(biggestClusterID);
final List<Uint8List> biggestSampledEmbeddingsProto =
_randomSampleWithoutReplacement(
@@ -1058,7 +1056,7 @@ class ClusterFeedbackService {
.toList(growable: false);
final Iterable<Uint8List> currentEmbeddings =
- await FaceMLDataDB.instance.getFaceEmbeddingsForCluster(clusterID);
+ await MLDataDB.instance.getFaceEmbeddingsForCluster(clusterID);
final List<Uint8List> currentSampledEmbeddingsProto =
_randomSampleWithoutReplacement(
currentEmbeddings,
@@ -1104,7 +1102,7 @@ class ClusterFeedbackService {
// Logging the blur values for the cluster
if (logBlurValues) {
- final List<double> blurValues = await FaceMLDataDB.instance
+ final List<double> blurValues = await MLDataDB.instance
.getBlurValuesForCluster(clusterID)
.then((value) => value.toList());
final blurValuesIntegers =
diff --git a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart
index e8a0b78fc6..a841d16b3e 100644
--- a/mobile/lib/services/machine_learning/face_ml/person/person_service.dart
+++ b/mobile/lib/services/machine_learning/face_ml/person/person_service.dart
@@ -14,7 +14,7 @@ import "package:shared_preferences/shared_preferences.dart";
class PersonService {
final EntityService entityService;
- final FaceMLDataDB faceMLDataDB;
+ final MLDataDB faceMLDataDB;
final SharedPreferences prefs;
PersonService(this.entityService, this.faceMLDataDB, this.prefs);
// instance
@@ -30,7 +30,7 @@ class PersonService {
static init(
EntityService entityService,
- FaceMLDataDB faceMLDataDB,
+ MLDataDB faceMLDataDB,
SharedPreferences prefs,
) {
_instance = PersonService(entityService, faceMLDataDB, prefs);
diff --git a/mobile/lib/services/machine_learning/ml_service.dart b/mobile/lib/services/machine_learning/ml_service.dart
index a2ef72b3f3..48a5d64ea5 100644
--- a/mobile/lib/services/machine_learning/ml_service.dart
+++ b/mobile/lib/services/machine_learning/ml_service.dart
@@ -125,7 +125,7 @@ class MLService {
await sync();
final int unclusteredFacesCount =
- await FaceMLDataDB.instance.getUnclusteredFaceCount();
+ await MLDataDB.instance.getUnclusteredFaceCount();
if (unclusteredFacesCount > _kForceClusteringFaceCount) {
_logger.info(
"There are $unclusteredFacesCount unclustered faces, doing clustering first",
@@ -220,13 +220,13 @@ class MLService {
_showClusteringIsHappening = true;
// Get a sense of the total number of faces in the database
- final int totalFaces = await FaceMLDataDB.instance
- .getTotalFaceCount(minFaceScore: minFaceScore);
+ final int totalFaces =
+ await MLDataDB.instance.getTotalFaceCount(minFaceScore: minFaceScore);
final fileIDToCreationTime =
await FilesDB.instance.getFileIDToCreationTime();
final startEmbeddingFetch = DateTime.now();
// read all embeddings
- final result = await FaceMLDataDB.instance.getFaceInfoForClustering(
+ final result = await MLDataDB.instance.getFaceInfoForClustering(
minScore: minFaceScore,
maxFaces: totalFaces,
);
@@ -251,7 +251,7 @@ class MLService {
// Get the current cluster statistics
final Map<String, (Uint8List, int)> oldClusterSummaries =
- await FaceMLDataDB.instance.getAllClusterSummary();
+ await MLDataDB.instance.getAllClusterSummary();
if (clusterInBuckets) {
const int bucketSize = 10000;
@@ -310,9 +310,9 @@ class MLService {
return;
}
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster);
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.clusterSummaryUpdate(clusteringResult.newClusterSummaries);
Bus.instance.fire(PeopleChangedEvent());
for (final faceInfo in faceInfoForClustering) {
@@ -355,9 +355,9 @@ class MLService {
_logger.info(
'Updating ${clusteringResult.newFaceIdToCluster.length} FaceIDs with clusterIDs in the DB',
);
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.updateFaceIdToClusterId(clusteringResult.newFaceIdToCluster);
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.clusterSummaryUpdate(clusteringResult.newClusterSummaries);
Bus.instance.fire(PeopleChangedEvent());
_logger.info('Done updating FaceIDs with clusterIDs in the DB, in '
@@ -484,7 +484,7 @@ class MLService {
'Skipped putting embedding because of error ${result.toJsonString()}',
);
}
- await FaceMLDataDB.instance.bulkInsertFaces(faces);
+ await MLDataDB.instance.bulkInsertFaces(faces);
}
if (result.clipRan) {
@@ -500,7 +500,7 @@ class MLService {
e,
s,
);
- await FaceMLDataDB.instance.bulkInsertFaces(
+ await MLDataDB.instance.bulkInsertFaces(
[Face.empty(instruction.file.uploadedFileID!, error: true)],
);
await SemanticSearchService.storeEmptyClipImageResult(
diff --git a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart
index b01d9d82c2..3efa3f410a 100644
--- a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart
+++ b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart
@@ -113,7 +113,7 @@ class SemanticSearchService {
}
Future<void> clearIndexes() async {
- await FaceMLDataDB.instance.deleteClipIndexes();
+ await MLDataDB.instance.deleteClipIndexes();
final preferences = await SharedPreferences.getInstance();
await preferences.remove("sync_time_embeddings_v3");
_logger.info("Indexes cleared");
@@ -122,7 +122,7 @@ class SemanticSearchService {
Future<void> _loadImageEmbeddings() async {
_logger.info("Pulling cached embeddings");
final startTime = DateTime.now();
- _cachedImageEmbeddings = await FaceMLDataDB.instance.getAll();
+ _cachedImageEmbeddings = await MLDataDB.instance.getAll();
final endTime = DateTime.now();
_logger.info(
"Loading ${_cachedImageEmbeddings.length} took: ${(endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch)}ms",
@@ -134,7 +134,7 @@ class SemanticSearchService {
Future<List<int>> _getFileIDsToBeIndexed() async {
final uploadedFileIDs = await getIndexableFileIDs();
- final embeddedFileIDs = await FaceMLDataDB.instance.getIndexedFileIds();
+ final embeddedFileIDs = await MLDataDB.instance.getIndexedFileIds();
embeddedFileIDs.removeWhere((key, value) => value < clipMlVersion);
return uploadedFileIDs.difference(embeddedFileIDs.keys.toSet()).toList();
@@ -187,7 +187,7 @@ class SemanticSearchService {
_logger.info(results.length.toString() + " results");
if (deletedEntries.isNotEmpty) {
- unawaited(FaceMLDataDB.instance.deleteEmbeddings(deletedEntries));
+ unawaited(MLDataDB.instance.deleteEmbeddings(deletedEntries));
}
return results;
@@ -230,7 +230,7 @@ class SemanticSearchService {
_logger.info(results.length.toString() + " results");
if (deletedEntries.isNotEmpty) {
- unawaited(FaceMLDataDB.instance.deleteEmbeddings(deletedEntries));
+ unawaited(MLDataDB.instance.deleteEmbeddings(deletedEntries));
}
final matchingFileIDs = <int>[];
@@ -262,12 +262,12 @@ class SemanticSearchService {
embedding: clipResult.embedding,
version: clipMlVersion,
);
- await FaceMLDataDB.instance.put(embedding);
+ await MLDataDB.instance.put(embedding);
}
static Future<void> storeEmptyClipImageResult(EnteFile entefile) async {
final embedding = ClipEmbedding.empty(entefile.uploadedFileID!);
- await FaceMLDataDB.instance.put(embedding);
+ await MLDataDB.instance.put(embedding);
}
Future<List<double>> _getTextEmbedding(String query) async {
diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dart
index 0949f4f0fd..86f4b7c52b 100644
--- a/mobile/lib/services/search_service.dart
+++ b/mobile/lib/services/search_service.dart
@@ -741,7 +741,7 @@ class SearchService {
) async {
_logger.info('getClusterFilesForPersonID $personID');
final Map<int, Set<String>> fileIdToClusterID =
- await FaceMLDataDB.instance.getFileIdToClusterIDSet(personID);
+ await MLDataDB.instance.getFileIdToClusterIDSet(personID);
_logger.info('faceDbDone getClusterFilesForPersonID $personID');
final Map<String, List<EnteFile>> clusterIDToFiles = {};
final allFiles = await getAllFiles();
@@ -766,11 +766,11 @@ class SearchService {
try {
debugPrint("getting faces");
final Map<int, Set<String>> fileIdToClusterID =
- await FaceMLDataDB.instance.getFileIdToClusterIds();
+ await MLDataDB.instance.getFileIdToClusterIds();
final Map<String, PersonEntity> personIdToPerson =
await PersonService.instance.getPersonsMap();
final clusterIDToPersonID =
- await FaceMLDataDB.instance.getClusterIDToPersonID();
+ await MLDataDB.instance.getClusterIDToPersonID();
final List<GenericSearchResult> facesResult = [];
final Map<String, List<EnteFile>> clusterIdToFiles = {};
diff --git a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart
index 08bef662ed..fa936b0818 100644
--- a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart
+++ b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart
@@ -59,7 +59,7 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {
children: [
MenuItemWidget(
captionedTextWidget: FutureBuilder<int>(
- future: FaceMLDataDB.instance.getIndexedFileCount(),
+ future: MLDataDB.instance.getIndexedFileCount(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return CaptionedTextWidget(
@@ -176,7 +176,7 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {
sectionOptionSpacing,
MenuItemWidget(
captionedTextWidget: FutureBuilder<double>(
- future: FaceMLDataDB.instance.getClusteredToIndexableFilesRatio(),
+ future: MLDataDB.instance.getClusteredToIndexableFilesRatio(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return CaptionedTextWidget(
@@ -266,7 +266,7 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {
firstButtonLabel: "Yes, confirm",
firstButtonOnTap: () async {
try {
- await FaceMLDataDB.instance.dropFeedbackTables();
+ await MLDataDB.instance.dropFeedbackTables();
Bus.instance.fire(PeopleChangedEvent());
showShortToast(context, "Done");
} catch (e, s) {
@@ -299,7 +299,7 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {
for (final PersonEntity p in persons) {
await PersonService.instance.deletePerson(p.remoteID);
}
- await FaceMLDataDB.instance.dropClustersAndPersonTable();
+ await MLDataDB.instance.dropClustersAndPersonTable();
Bus.instance.fire(PeopleChangedEvent());
showShortToast(context, "Done");
} catch (e, s) {
@@ -327,7 +327,7 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {
firstButtonLabel: "Yes, confirm",
firstButtonOnTap: () async {
try {
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.dropClustersAndPersonTable(faces: true);
Bus.instance.fire(PeopleChangedEvent());
showShortToast(context, "Done");
diff --git a/mobile/lib/ui/viewer/file_details/face_widget.dart b/mobile/lib/ui/viewer/file_details/face_widget.dart
index 3ab4dac6ca..04572588c2 100644
--- a/mobile/lib/ui/viewer/file_details/face_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/face_widget.dart
@@ -73,12 +73,12 @@ class _FaceWidgetState extends State<FaceWidget> {
// Get faceID and double check that it doesn't belong to an existing clusterID. If it does, push that cluster page
final w = (kDebugMode ? EnteWatch('FaceWidget') : null)
?..start();
- final existingClusterID = await FaceMLDataDB.instance
+ final existingClusterID = await MLDataDB.instance
.getClusterIDForFaceID(widget.face.faceID);
w?.log('getting existing clusterID for faceID');
if (existingClusterID != null) {
final fileIdsToClusterIds =
- await FaceMLDataDB.instance.getFileIdToClusterIds();
+ await MLDataDB.instance.getFileIdToClusterIds();
final files = await SearchService.instance.getAllFiles();
final clusterFiles = files
.where(
@@ -100,7 +100,7 @@ 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();
- await FaceMLDataDB.instance.updateFaceIdToClusterId(
+ await MLDataDB.instance.updateFaceIdToClusterId(
{widget.face.faceID: newClusterID},
);
@@ -124,7 +124,7 @@ class _FaceWidgetState extends State<FaceWidget> {
);
} else if (widget.clusterID != null) {
final fileIdsToClusterIds =
- await FaceMLDataDB.instance.getFileIdToClusterIds();
+ await MLDataDB.instance.getFileIdToClusterIds();
final files = await SearchService.instance.getAllFiles();
final clusterFiles = files
.where(
diff --git a/mobile/lib/ui/viewer/file_details/faces_item_widget.dart b/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
index 8b12547b26..d2c0735ef0 100644
--- a/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
+++ b/mobile/lib/ui/viewer/file_details/faces_item_widget.dart
@@ -66,8 +66,8 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
];
}
- final List<Face>? faces = await FaceMLDataDB.instance
- .getFacesForGivenFileID(file.uploadedFileID!);
+ final List<Face>? faces =
+ await MLDataDB.instance.getFacesForGivenFileID(file.uploadedFileID!);
if (faces == null) {
return [
const ChipButtonWidget(
@@ -93,12 +93,12 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {
];
}
- final faceIdsToClusterIds = await FaceMLDataDB.instance
+ final faceIdsToClusterIds = await MLDataDB.instance
.getFaceIdsToClusterIds(faces.map((face) => face.faceID));
final Map<String, PersonEntity> persons =
await PersonService.instance.getPersonsMap();
final clusterIDToPerson =
- await FaceMLDataDB.instance.getClusterIDToPersonID();
+ await MLDataDB.instance.getClusterIDToPersonID();
// Sort faces by name and score
final faceIdToPersonID = <String, String>{};
diff --git a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart b/mobile/lib/ui/viewer/people/add_person_action_sheet.dart
index cb8dfe797a..2098a886b0 100644
--- a/mobile/lib/ui/viewer/people/add_person_action_sheet.dart
+++ b/mobile/lib/ui/viewer/people/add_person_action_sheet.dart
@@ -248,7 +248,7 @@ class _PersonActionSheetState extends State<PersonActionSheet> {
return;
}
userAlreadyAssigned = true;
- await FaceMLDataDB.instance.assignClusterToPerson(
+ await MLDataDB.instance.assignClusterToPerson(
personID: person.$1.remoteID,
clusterID: widget.cluserID,
);
diff --git a/mobile/lib/ui/viewer/people/cluster_app_bar.dart b/mobile/lib/ui/viewer/people/cluster_app_bar.dart
index 05df78c390..a5e6ef7815 100644
--- a/mobile/lib/ui/viewer/people/cluster_app_bar.dart
+++ b/mobile/lib/ui/viewer/people/cluster_app_bar.dart
@@ -196,10 +196,10 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
breakupResult.newFaceIdToCluster;
// Update to delete the old clusters and save the new clusters
- await FaceMLDataDB.instance.deleteClusterSummary(widget.clusterID);
- await FaceMLDataDB.instance
+ await MLDataDB.instance.deleteClusterSummary(widget.clusterID);
+ await MLDataDB.instance
.clusterSummaryUpdate(breakupResult.newClusterSummaries);
- await FaceMLDataDB.instance
+ await MLDataDB.instance
.updateFaceIdToClusterId(newFaceIdToClusterID);
// Find the biggest cluster
diff --git a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart
index 0c5a4ccbf1..54ff9975e8 100644
--- a/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart
+++ b/mobile/lib/ui/viewer/people/person_cluster_suggestion.dart
@@ -199,7 +199,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
);
if (yesOrNo) {
canGiveFeedback = false;
- await FaceMLDataDB.instance.assignClusterToPerson(
+ await MLDataDB.instance.assignClusterToPerson(
personID: widget.person.remoteID,
clusterID: clusterID,
);
@@ -233,7 +233,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
int numberOfSuggestions,
) async {
canGiveFeedback = false;
- await FaceMLDataDB.instance.captureNotPersonFeedback(
+ await MLDataDB.instance.captureNotPersonFeedback(
personID: widget.person.remoteID,
clusterID: clusterID,
);
@@ -489,7 +489,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {
clusterID: lastFeedback.suggestion.clusterIDToMerge,
);
} else {
- await FaceMLDataDB.instance.removeNotPersonFeedback(
+ await MLDataDB.instance.removeNotPersonFeedback(
personID: widget.person.remoteID,
clusterID: lastFeedback.suggestion.clusterIDToMerge,
);
diff --git a/mobile/lib/ui/viewer/search/result/person_face_widget.dart b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
index 1b812dd36a..b5e9882833 100644
--- a/mobile/lib/ui/viewer/search/result/person_face_widget.dart
+++ b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
@@ -86,7 +86,7 @@ class PersonFaceWidget extends StatelessWidget {
personAvatarFaceID = personEntity.data.avatarFaceID;
}
}
- return await FaceMLDataDB.instance.getCoverFaceForPerson(
+ return await MLDataDB.instance.getCoverFaceForPerson(
recentFileID: file.uploadedFileID!,
avatarFaceId: personAvatarFaceID,
personID: personId,
@@ -174,7 +174,7 @@ class PersonFaceWidget extends StatelessWidget {
required bool useFullFile,
}) async {
try {
- final Face? face = await FaceMLDataDB.instance.getCoverFaceForPerson(
+ final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
recentFileID: file.uploadedFileID!,
clusterID: clusterID,
);
diff --git a/mobile/lib/utils/ml_util.dart b/mobile/lib/utils/ml_util.dart
index 5b68b9c819..dffca632bd 100644
--- a/mobile/lib/utils/ml_util.dart
+++ b/mobile/lib/utils/ml_util.dart
@@ -52,9 +52,9 @@ Future<IndexStatus> getIndexStatus() async {
try {
final int indexableFiles = (await getIndexableFileIDs()).length;
final int facesIndexedFiles =
- await FaceMLDataDB.instance.getIndexedFileCount();
+ await MLDataDB.instance.getIndexedFileCount();
final int clipIndexedFiles =
- await FaceMLDataDB.instance.getClipIndexedFileCount();
+ await MLDataDB.instance.getClipIndexedFileCount();
final int indexedFiles = math.min(facesIndexedFiles, clipIndexedFiles);
final showIndexedFiles = math.min(indexedFiles, indexableFiles);
@@ -71,9 +71,9 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
final time = DateTime.now();
// Get indexed fileIDs for each ML service
final Map<int, int> faceIndexedFileIDs =
- await FaceMLDataDB.instance.getIndexedFileIds();
+ await MLDataDB.instance.getIndexedFileIds();
final Map<int, int> clipIndexedFileIDs =
- await FaceMLDataDB.instance.clipIndexedFileWithVersion();
+ await MLDataDB.instance.clipIndexedFileWithVersion();
// Get all regular files and all hidden files
final enteFiles = await SearchService.instance.getAllFiles();