[mob] Rename method

This commit is contained in:
Neeraj Gupta
2024-07-19 16:02:19 +05:30
parent 0a3c61515f
commit 1e15825617
2 changed files with 56 additions and 58 deletions

View File

@@ -101,7 +101,7 @@ class FaceRecognitionService {
.toSet();
_logger.info('starting remote fetch for ${fileIds.length} files');
final res =
await RemoteFileMLService.instance.getFilessEmbedding(fileIds);
await RemoteFileMLService.instance.getFaceEmbedding(fileIds);
_logger.info('fetched ${res.mlData.length} embeddings');
fetchedCount += res.mlData.length;
final List<Face> faces = [];

View File

@@ -56,7 +56,7 @@ class RemoteFileMLService {
}
}
Future<FilesMLDataResponse> getFilessEmbedding(
Future<FilesMLDataResponse> getFaceEmbedding(
Set<int> fileIds,
) async {
try {
@@ -119,68 +119,66 @@ class RemoteFileMLService {
},
);
}
}
Future<Map<int, FileMl>> _decryptFileMLComputer(
Map<String, dynamic> args,
) async {
final result = <int, FileMl>{};
final inputs = args["inputs"] as List<EmbeddingsDecoderInput>;
for (final input in inputs) {
final decryptArgs = <String, dynamic>{};
decryptArgs["source"] =
CryptoUtil.base642bin(input.embedding.encryptedEmbedding);
decryptArgs["key"] = input.decryptionKey;
decryptArgs["header"] =
CryptoUtil.base642bin(input.embedding.decryptionHeader);
final embeddingData = chachaDecryptData(decryptArgs);
final decodedJson = jsonDecode(utf8.decode(embeddingData));
final FileMl decodedEmbedding =
FileMl.fromJson(decodedJson as Map<String, dynamic>);
result[input.embedding.fileID] = decodedEmbedding;
}
return result;
Map<String, dynamic> args,
) async {
final result = <int, FileMl>{};
final inputs = args["inputs"] as List<EmbeddingsDecoderInput>;
for (final input in inputs) {
final decryptArgs = <String, dynamic>{};
decryptArgs["source"] =
CryptoUtil.base642bin(input.embedding.encryptedEmbedding);
decryptArgs["key"] = input.decryptionKey;
decryptArgs["header"] =
CryptoUtil.base642bin(input.embedding.decryptionHeader);
final embeddingData = chachaDecryptData(decryptArgs);
final decodedJson = jsonDecode(utf8.decode(embeddingData));
final FileMl decodedEmbedding =
FileMl.fromJson(decodedJson as Map<String, dynamic>);
result[input.embedding.fileID] = decodedEmbedding;
}
return result;
}
bool shouldDiscardRemoteEmbedding(FileMl fileMl) {
if (fileMl.faceEmbedding.version < faceMlVersion) {
debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} "
"because version is ${fileMl.faceEmbedding.version} and we need $faceMlVersion");
return true;
}
// are all landmarks equal?
bool allLandmarksEqual = true;
if (fileMl.faceEmbedding.faces.isEmpty) {
debugPrint("No face for ${fileMl.fileID}");
if (fileMl.faceEmbedding.version < faceMlVersion) {
debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} "
"because version is ${fileMl.faceEmbedding.version} and we need $faceMlVersion");
return true;
}
// are all landmarks equal?
bool allLandmarksEqual = true;
if (fileMl.faceEmbedding.faces.isEmpty) {
debugPrint("No face for ${fileMl.fileID}");
allLandmarksEqual = false;
}
for (final face in fileMl.faceEmbedding.faces) {
if (face.detection.landmarks.isEmpty) {
allLandmarksEqual = false;
break;
}
for (final face in fileMl.faceEmbedding.faces) {
if (face.detection.landmarks.isEmpty) {
allLandmarksEqual = false;
break;
}
if (face.detection.landmarks
.any((landmark) => landmark.x != landmark.y)) {
allLandmarksEqual = false;
break;
}
if (face.detection.landmarks.any((landmark) => landmark.x != landmark.y)) {
allLandmarksEqual = false;
break;
}
if (allLandmarksEqual) {
debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} "
"because landmarks are equal");
debugPrint(
fileMl.faceEmbedding.faces
.map((e) => e.detection.landmarks.toString())
.toList()
.toString(),
);
return true;
}
if (fileMl.width == null || fileMl.height == null) {
debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} "
"because width is null");
return true;
}
return false;
}
}
if (allLandmarksEqual) {
debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} "
"because landmarks are equal");
debugPrint(
fileMl.faceEmbedding.faces
.map((e) => e.detection.landmarks.toString())
.toList()
.toString(),
);
return true;
}
if (fileMl.width == null || fileMl.height == null) {
debugPrint("Discarding remote embedding for fileID ${fileMl.fileID} "
"because width is null");
return true;
}
return false;
}