mirror of
https://github.com/ente-io/ente.git
synced 2025-08-07 23:18:10 +00:00
[mob][photos] Small changes
This commit is contained in:
parent
e65b4643cd
commit
ff5dc490f8
@ -5,7 +5,6 @@ import "dart:isolate";
|
||||
import "dart:math" show min;
|
||||
import "dart:typed_data" show Uint8List, ByteData;
|
||||
|
||||
import "package:computer/computer.dart";
|
||||
import "package:dart_ui_isolate/dart_ui_isolate.dart";
|
||||
import "package:flutter/foundation.dart" show debugPrint;
|
||||
import "package:logging/logging.dart";
|
||||
@ -68,8 +67,6 @@ class FaceMlService {
|
||||
final _functionLock = Lock();
|
||||
final _initIsolateLock = Lock();
|
||||
|
||||
final _computer = Computer.shared();
|
||||
|
||||
bool _isInitialized = false;
|
||||
bool _isModelsInitialized = false;
|
||||
bool _isIsolateSpawned = false;
|
||||
@ -132,6 +129,7 @@ class FaceMlService {
|
||||
|
||||
Future<void> sync() async {
|
||||
await FaceRecognitionService.instance.sync();
|
||||
await SemanticSearchService.instance.sync();
|
||||
}
|
||||
|
||||
Future<void> runAllFaceML({bool force = false}) async {
|
||||
@ -385,7 +383,8 @@ class FaceMlService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> processImage(FileMLInstruction instruction) async { // TODO: clean this function up
|
||||
Future<bool> processImage(FileMLInstruction instruction) async {
|
||||
// TODO: clean this function up
|
||||
_logger.info(
|
||||
"`processImage` start processing image with uploadedFileID: ${instruction.enteFile.uploadedFileID}",
|
||||
);
|
||||
|
@ -52,8 +52,10 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
|
||||
final List<FileMLInstruction> hiddenFilesToIndex = [];
|
||||
for (final EnteFile enteFile in enteFiles) {
|
||||
final skip = _skipAnalysisEnteFile(enteFile);
|
||||
final shouldRunFaces = _shouldRunIndexing(enteFile, faceIndexedFileIDs);
|
||||
final shouldRunClip = _shouldRunIndexing(enteFile, clipIndexedFileIDs);
|
||||
final shouldRunFaces =
|
||||
_shouldRunIndexing(enteFile, faceIndexedFileIDs, faceMlVersion);
|
||||
final shouldRunClip =
|
||||
_shouldRunIndexing(enteFile, clipIndexedFileIDs, clipMlVersion);
|
||||
if (skip && !shouldRunFaces && !shouldRunClip) {
|
||||
continue;
|
||||
}
|
||||
@ -70,8 +72,10 @@ Future<List<FileMLInstruction>> getFilesForMlIndexing() async {
|
||||
}
|
||||
for (final EnteFile enteFile in hiddenFiles) {
|
||||
final skip = _skipAnalysisEnteFile(enteFile);
|
||||
final shouldRunFaces = _shouldRunIndexing(enteFile, faceIndexedFileIDs);
|
||||
final shouldRunClip = _shouldRunIndexing(enteFile, clipIndexedFileIDs);
|
||||
final shouldRunFaces =
|
||||
_shouldRunIndexing(enteFile, faceIndexedFileIDs, faceMlVersion);
|
||||
final shouldRunClip =
|
||||
_shouldRunIndexing(enteFile, clipIndexedFileIDs, clipMlVersion);
|
||||
if (skip && !shouldRunFaces && !shouldRunClip) {
|
||||
continue;
|
||||
}
|
||||
@ -100,65 +104,38 @@ Future<Set<int>> getIndexableFileIDs() async {
|
||||
return fileIDs.toSet();
|
||||
}
|
||||
|
||||
Future<String> getImagePathForML(
|
||||
EnteFile enteFile, {
|
||||
FileDataForML typeOfData = FileDataForML.fileData,
|
||||
}) async {
|
||||
Future<String> getImagePathForML(EnteFile enteFile) async {
|
||||
String? imagePath;
|
||||
|
||||
switch (typeOfData) {
|
||||
case FileDataForML.fileData:
|
||||
final stopwatch = Stopwatch()..start();
|
||||
File? file;
|
||||
if (enteFile.fileType == FileType.video) {
|
||||
try {
|
||||
file = await getThumbnailForUploadedFile(enteFile);
|
||||
} on PlatformException catch (e, s) {
|
||||
_logger.severe(
|
||||
"Could not get thumbnail for $enteFile due to PlatformException",
|
||||
e,
|
||||
s,
|
||||
);
|
||||
throw ThumbnailRetrievalException(e.toString(), s);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
file = await getFile(enteFile, isOrigin: true);
|
||||
} catch (e, s) {
|
||||
_logger.severe(
|
||||
"Could not get file for $enteFile",
|
||||
e,
|
||||
s,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (file == null) {
|
||||
_logger.warning(
|
||||
"Could not get file for $enteFile of type ${enteFile.fileType.toString()}",
|
||||
);
|
||||
break;
|
||||
}
|
||||
imagePath = file.path;
|
||||
stopwatch.stop();
|
||||
_logger.info(
|
||||
"Getting file data for uploadedFileID ${enteFile.uploadedFileID} took ${stopwatch.elapsedMilliseconds} ms",
|
||||
final stopwatch = Stopwatch()..start();
|
||||
File? file;
|
||||
if (enteFile.fileType == FileType.video) {
|
||||
try {
|
||||
file = await getThumbnailForUploadedFile(enteFile);
|
||||
} on PlatformException catch (e, s) {
|
||||
_logger.severe(
|
||||
"Could not get thumbnail for $enteFile due to PlatformException",
|
||||
e,
|
||||
s,
|
||||
);
|
||||
break;
|
||||
|
||||
case FileDataForML.thumbnailData:
|
||||
final stopwatch = Stopwatch()..start();
|
||||
final File? thumbnail = await getThumbnailForUploadedFile(enteFile);
|
||||
if (thumbnail == null) {
|
||||
_logger.warning("Could not get thumbnail for $enteFile");
|
||||
break;
|
||||
}
|
||||
imagePath = thumbnail.path;
|
||||
stopwatch.stop();
|
||||
_logger.info(
|
||||
"Getting thumbnail data for uploadedFileID ${enteFile.uploadedFileID} took ${stopwatch.elapsedMilliseconds} ms",
|
||||
throw ThumbnailRetrievalException(e.toString(), s);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
file = await getFile(enteFile, isOrigin: true);
|
||||
} catch (e, s) {
|
||||
_logger.severe(
|
||||
"Could not get file for $enteFile",
|
||||
e,
|
||||
s,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
imagePath = file?.path;
|
||||
stopwatch.stop();
|
||||
_logger.info(
|
||||
"Getting file data for uploadedFileID ${enteFile.uploadedFileID} took ${stopwatch.elapsedMilliseconds} ms",
|
||||
);
|
||||
|
||||
if (imagePath == null) {
|
||||
_logger.warning(
|
||||
@ -182,9 +159,13 @@ bool _skipAnalysisEnteFile(EnteFile enteFile) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool _shouldRunIndexing(EnteFile enteFile, Map<int, int> indexedFileIds) {
|
||||
bool _shouldRunIndexing(
|
||||
EnteFile enteFile,
|
||||
Map<int, int> indexedFileIds,
|
||||
int newestVersion,
|
||||
) {
|
||||
final id = enteFile.uploadedFileID!;
|
||||
return !indexedFileIds.containsKey(id) || indexedFileIds[id]! < faceMlVersion;
|
||||
return !indexedFileIds.containsKey(id) || indexedFileIds[id]! < newestVersion;
|
||||
}
|
||||
|
||||
void normalizeEmbedding(List<double> embedding) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user