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