[mob] Handle missing fileIDs during clustering

This commit is contained in:
Neeraj Gupta 2024-05-10 13:25:22 +05:30
parent 4db3c9fe95
commit c906480dee
2 changed files with 17 additions and 9 deletions

View file

@ -525,7 +525,7 @@ class FaceMLDataDB {
);
final db = await instance.asyncDB;
final List<FaceInfoForClustering> result = {};
final List<FaceInfoForClustering> result = <FaceInfoForClustering>[];
while (true) {
// Query a batch of rows
final List<Map<String, dynamic>> maps = await db.getAll(
@ -563,7 +563,7 @@ class FaceMLDataDB {
w.stopWithLog('done reading face embeddings ${result.length}');
return result;
} catch (e) {
_logger.severe('Error in getFaceInfoForClustering', e);
_logger.severe('err in getFaceInfoForClustering', e);
rethrow;
}
}

View file

@ -28,6 +28,7 @@ import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/ml/ml_versions.dart";
import 'package:photos/services/machine_learning/face_ml/face_clustering/face_clustering_service.dart';
import "package:photos/services/machine_learning/face_ml/face_clustering/face_info_for_clustering.dart";
import 'package:photos/services/machine_learning/face_ml/face_detection/detection.dart';
import 'package:photos/services/machine_learning/face_ml/face_detection/face_detection_exceptions.dart';
import 'package:photos/services/machine_learning/face_ml/face_detection/face_detection_service.dart';
@ -308,20 +309,27 @@ class FaceMlService {
await FilesDB.instance.getFileIDToCreationTime();
final startEmbeddingFetch = DateTime.now();
// read all embeddings
final allFaceInfoForClustering =
await FaceMLDataDB.instance.getFaceInfoForClustering(
final result = await FaceMLDataDB.instance.getFaceInfoForClustering(
minScore: minFaceScore,
maxFaces: totalFaces,
);
final Set<int> missingFileIDs = {};
final allFaceInfoForClustering = <FaceInfoForClustering>[];
for (final faceInfo in result) {
if (!fileIDToCreationTime.containsKey(faceInfo.fileID)) {
missingFileIDs.add(faceInfo.fileID);
} else {
allFaceInfoForClustering.add(faceInfo);
}
}
// sort the embeddings based on file creation time, oldest first
allFaceInfoForClustering.sort((a, b) {
final aFileId = getFileIdFromFaceId(a.faceID);
final bFileId = getFileIdFromFaceId(b.faceID);
return fileIDToCreationTime[aFileId]!
.compareTo(fileIDToCreationTime[bFileId]!);
return fileIDToCreationTime[a.fileID]!
.compareTo(fileIDToCreationTime[b.fileID]!);
});
_logger.info(
'Getting and sorting embeddings took ${DateTime.now().difference(startEmbeddingFetch).inMilliseconds} ms',
'Getting and sorting embeddings took ${DateTime.now().difference(startEmbeddingFetch).inMilliseconds} ms for ${allFaceInfoForClustering.length} embeddings'
'and ${missingFileIDs.length} missing fileIDs',
);
// Get the current cluster statistics