|
@@ -1,4 +1,5 @@
|
|
|
import 'dart:async';
|
|
|
+import "dart:convert" show json;
|
|
|
import "dart:io" show Directory;
|
|
|
import "dart:math";
|
|
|
|
|
@@ -10,6 +11,7 @@ import 'package:path_provider/path_provider.dart';
|
|
|
import "package:photos/extensions/stop_watch.dart";
|
|
|
import 'package:photos/face/db_fields.dart';
|
|
|
import "package:photos/face/db_model_mappers.dart";
|
|
|
+import "package:photos/face/model/detection.dart";
|
|
|
import "package:photos/face/model/face.dart";
|
|
|
import "package:photos/models/file/file.dart";
|
|
|
import "package:photos/services/machine_learning/face_ml/face_clustering/face_info_for_clustering.dart";
|
|
@@ -455,6 +457,31 @@ class FaceMLDataDB {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ // TODO: remove this method and replace by correct logic during indexing
|
|
|
+ Future<Map<String, bool>> getFaceIdsToIsSidewaysFaceTEMP() async {
|
|
|
+ final db = await instance.sqliteAsyncDB;
|
|
|
+ final List<Map<String, dynamic>> maps = await db.getAll(
|
|
|
+ 'SELECT $faceIDColumn, $faceDetectionColumn FROM $facesTable',
|
|
|
+ );
|
|
|
+
|
|
|
+ final time = DateTime.now();
|
|
|
+ final Map<String, bool> result = {};
|
|
|
+ for (final map in maps) {
|
|
|
+ final faceID = map[faceIDColumn] as String;
|
|
|
+ final detection =
|
|
|
+ Detection.fromJson(json.decode(map[faceDetectionColumn] as String));
|
|
|
+ result[faceID] = detection.faceIsSideways();
|
|
|
+ }
|
|
|
+ _logger.info(
|
|
|
+ 'decoding detections and calculating face sideways bools took ${DateTime.now().difference(time).inMilliseconds} ms',
|
|
|
+ );
|
|
|
+ final double sidewaysRatio =
|
|
|
+ result.values.where((e) => e).length / result.length;
|
|
|
+ _logger.info('sideways face ratio: $sidewaysRatio');
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
Future<Set<FaceInfoForClustering>> getFaceInfoForClustering({
|
|
|
double minScore = kMinHighQualityFaceScore,
|
|
|
int minClarity = kLaplacianHardThreshold,
|
|
@@ -468,6 +495,9 @@ class FaceMLDataDB {
|
|
|
);
|
|
|
final db = await instance.sqliteAsyncDB;
|
|
|
|
|
|
+ final Map<String, bool> faceIdsToIsSideways =
|
|
|
+ await getFaceIdsToIsSidewaysFaceTEMP();
|
|
|
+
|
|
|
final Set<FaceInfoForClustering> result = {};
|
|
|
while (true) {
|
|
|
// Query a batch of rows
|
|
@@ -494,6 +524,7 @@ class FaceMLDataDB {
|
|
|
embeddingBytes: map[faceEmbeddingBlob] as Uint8List,
|
|
|
faceScore: map[faceScore] as double,
|
|
|
blurValue: map[faceBlur] as double,
|
|
|
+ isSideways: faceIdsToIsSideways[faceID] ?? false,
|
|
|
);
|
|
|
result.add(faceInfo);
|
|
|
}
|