[mob] Debug option to get clusters of blur values
This commit is contained in:
parent
d4d9253f1a
commit
f61a5f91b6
3 changed files with 75 additions and 0 deletions
|
@ -364,6 +364,20 @@ class FaceMLDataDB {
|
|||
return maps.map((e) => e[faceBlur] as double).toSet();
|
||||
}
|
||||
|
||||
Future<Map<String, double>> getFaceIDsToBlurValues(
|
||||
int maxBlurValue,
|
||||
) async {
|
||||
final db = await instance.sqliteAsyncDB;
|
||||
final List<Map<String, dynamic>> maps = await db.getAll(
|
||||
'SELECT $faceIDColumn, $faceBlur FROM $facesTable WHERE $faceBlur < $maxBlurValue AND $faceBlur > 1 ORDER BY $faceBlur ASC',
|
||||
);
|
||||
final Map<String, double> result = {};
|
||||
for (final map in maps) {
|
||||
result[map[faceIDColumn] as String] = map[faceBlur] as double;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<Map<String, int?>> getFaceIdsToClusterIds(
|
||||
Iterable<String> faceIds,
|
||||
) async {
|
||||
|
|
|
@ -295,6 +295,38 @@ class ClusterFeedbackService {
|
|||
return clusterIdToFaceIds;
|
||||
}
|
||||
|
||||
/// WARNING: this method is purely for debugging purposes, never use in production
|
||||
Future<void> createFakeClustersByBlurValue() async {
|
||||
try {
|
||||
// Delete old clusters
|
||||
await FaceMLDataDB.instance.resetClusterIDs();
|
||||
await FaceMLDataDB.instance.dropClustersAndPersonTable();
|
||||
final List<PersonEntity> persons =
|
||||
await PersonService.instance.getPersons();
|
||||
for (final PersonEntity p in persons) {
|
||||
await PersonService.instance.deletePerson(p.remoteID);
|
||||
}
|
||||
|
||||
// Create new fake clusters based on blur value. One for values between 0 and 10, one for 10-20, etc till 200
|
||||
final int startClusterID = DateTime.now().microsecondsSinceEpoch;
|
||||
final faceIDsToBlurValues =
|
||||
await FaceMLDataDB.instance.getFaceIDsToBlurValues(200);
|
||||
final faceIdToCluster = <String, int>{};
|
||||
for (final entry in faceIDsToBlurValues.entries) {
|
||||
final faceID = entry.key;
|
||||
final blurValue = entry.value;
|
||||
final newClusterID = startClusterID + blurValue ~/ 10;
|
||||
faceIdToCluster[faceID] = newClusterID;
|
||||
}
|
||||
await FaceMLDataDB.instance.updateClusterIdToFaceId(faceIdToCluster);
|
||||
|
||||
Bus.instance.fire(PeopleChangedEvent());
|
||||
} catch (e, s) {
|
||||
_logger.severe("Error in createFakeClustersByBlurValue", e, s);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> debugLogClusterBlurValues(
|
||||
int clusterID, {
|
||||
int? clusterSize,
|
||||
|
|
|
@ -8,6 +8,7 @@ import "package:photos/events/people_changed_event.dart";
|
|||
import "package:photos/face/db.dart";
|
||||
import "package:photos/face/model/person.dart";
|
||||
import 'package:photos/services/machine_learning/face_ml/face_ml_service.dart';
|
||||
import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedback.dart";
|
||||
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/captioned_text_widget.dart';
|
||||
|
@ -284,6 +285,34 @@ class _FaceDebugSectionWidgetState extends State<FaceDebugSectionWidget> {
|
|||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: const CaptionedTextWidget(
|
||||
title: "Rank blurs",
|
||||
),
|
||||
pressedColor: getEnteColorScheme(context).fillFaint,
|
||||
trailingIcon: Icons.chevron_right_outlined,
|
||||
trailingIconIsMuted: true,
|
||||
onTap: () async {
|
||||
await showChoiceDialog(
|
||||
context,
|
||||
title: "Are you sure?",
|
||||
body:
|
||||
"This will delete all clusters and put blurry faces in separate clusters per ten points.",
|
||||
firstButtonLabel: "Yes, confirm",
|
||||
firstButtonOnTap: () async {
|
||||
try {
|
||||
await ClusterFeedbackService.instance
|
||||
.createFakeClustersByBlurValue();
|
||||
showShortToast(context, "Done");
|
||||
} catch (e, s) {
|
||||
_logger.warning('Failed to rank faces on blur values ', e, s);
|
||||
await showGenericErrorDialog(context: context, error: e);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: const CaptionedTextWidget(
|
||||
title: "Drop embeddings & feedback",
|
||||
|
|
Loading…
Add table
Reference in a new issue