Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove dead code

Neeraj Gupta2ba802d59f46
diff --git a/mobile/lib/services/object_detection/models/predictions.dart b/mobile/lib/services/object_detection/models/predictions.dart
deleted file mode 100644
index 4957fd8cb8..0000000000
--- a/mobile/lib/services/object_detection/models/predictions.dart
+++ /dev/null
@@ -1,14 +0,0 @@
-import "package:photos/services/object_detection/models/recognition.dart";
-import "package:photos/services/object_detection/models/stats.dart";
-
-class Predictions {
- final List<Recognition>? recognitions;
- final Stats? stats;
- final Object? error;
-
- Predictions(
- this.recognitions,
- this.stats, {
- this.error,
- });
-}
diff --git a/mobile/lib/services/object_detection/models/recognition.dart b/mobile/lib/services/object_detection/models/recognition.dart
deleted file mode 100644
index 3a76c2d565..0000000000
--- a/mobile/lib/services/object_detection/models/recognition.dart
+++ /dev/null
@@ -1,18 +0,0 @@
-/// Represents the recognition output from the model
-class Recognition {
- /// Index of the result
- final int id;
-
- /// Label of the result
- final String label;
-
- /// Confidence [0.0, 1.0]
- final double score;
-
- Recognition(this.id, this.label, this.score);
-
- @override
- String toString() {
- return 'Recognition(id: $id, label: $label, score: $score)';
- }
-}
diff --git a/mobile/lib/services/object_detection/models/stats.dart b/mobile/lib/services/object_detection/models/stats.dart
deleted file mode 100644
index 6397f42428..0000000000
--- a/mobile/lib/services/object_detection/models/stats.dart
+++ /dev/null
@@ -1,27 +0,0 @@
-/// Bundles different elapsed times
-class Stats {
- /// Total time taken in the isolate where the inference runs
- final int totalPredictTime;
-
- /// [totalPredictTime] + communication overhead time
- /// between main isolate and another isolate
- final int totalElapsedTime;
-
- /// Time for which inference runs
- final int inferenceTime;
-
- /// Time taken to pre-process the image
- final int preProcessingTime;
-
- Stats(
- this.totalPredictTime,
- this.totalElapsedTime,
- this.inferenceTime,
- this.preProcessingTime,
- );
-
- @override
- String toString() {
- return 'Stats{totalPredictTime: $totalPredictTime, totalElapsedTime: $totalElapsedTime, inferenceTime: $inferenceTime, preProcessingTime: $preProcessingTime}';
- }
-}
diff --git a/mobile/lib/services/object_detection/object_detection_service.dart b/mobile/lib/services/object_detection/object_detection_service.dart
deleted file mode 100644
index 360747f952..0000000000
--- a/mobile/lib/services/object_detection/object_detection_service.dart
+++ /dev/null
@@ -1,157 +0,0 @@
-// import "dart:isolate";
-// import "dart:math";
-// import "dart:typed_data";
-
-// import "package:logging/logging.dart";
-// import "package:photos/services/object_detection/models/predictions.dart";
-// import 'package:photos/services/object_detection/models/recognition.dart';
-// import 'package:photos/services/object_detection/tflite/cocossd_classifier.dart';
-// import "package:photos/services/object_detection/tflite/mobilenet_classifier.dart";
-// import "package:photos/services/object_detection/tflite/scene_classifier.dart";
-// import "package:photos/services/object_detection/utils/isolate_utils.dart";
-
-// class ObjectDetectionService {
-// static const scoreThreshold = 0.35;
-
-// final _logger = Logger("ObjectDetectionService");
-
-// late CocoSSDClassifier _objectClassifier;
-// late MobileNetClassifier _mobileNetClassifier;
-// late SceneClassifier _sceneClassifier;
-
-// late IsolateUtils _isolateUtils;
-
-// ObjectDetectionService._privateConstructor();
-// bool inInitiated = false;
-
-// Future<void> init() async {
-// _isolateUtils = IsolateUtils();
-// await _isolateUtils.start();
-// try {
-// _objectClassifier = CocoSSDClassifier();
-// } catch (e, s) {
-// _logger.severe("Could not initialize cocossd", e, s);
-// }
-// try {
-// _mobileNetClassifier = MobileNetClassifier();
-// } catch (e, s) {
-// _logger.severe("Could not initialize mobilenet", e, s);
-// }
-// try {
-// _sceneClassifier = SceneClassifier();
-// } catch (e, s) {
-// _logger.severe("Could not initialize sceneclassifier", e, s);
-// }
-// inInitiated = true;
-// }
-
-// static ObjectDetectionService instance =
-// ObjectDetectionService._privateConstructor();
-
-// Future<Map<String, double>> predict(Uint8List bytes) async {
-// try {
-// if (!inInitiated) {
-// return Future.error("ObjectDetectionService init is not completed");
-// }
-// final results = <String, double>{};
-// final methods = [_getObjects, _getMobileNetResults, _getSceneResults];
-
-// for (var method in methods) {
-// final methodResults = await method(bytes);
-// methodResults.forEach((key, value) {
-// results.update(
-// key,
-// (existingValue) => max(existingValue, value),
-// ifAbsent: () => value,
-// );
-// });
-// }
-// return results;
-// } catch (e, s) {
-// _logger.severe(e, s);
-// rethrow;
-// }
-// }
-
-// Future<Map<String, double>> _getObjects(Uint8List bytes) async {
-// try {
-// final isolateData = IsolateData(
-// bytes,
-// _objectClassifier.interpreter.address,
-// _objectClassifier.labels,
-// ClassifierType.cocossd,
-// );
-// return _getPredictions(isolateData);
-// } catch (e, s) {
-// _logger.severe("Could not run cocossd", e, s);
-// }
-// return {};
-// }
-
-// Future<Map<String, double>> _getMobileNetResults(Uint8List bytes) async {
-// try {
-// final isolateData = IsolateData(
-// bytes,
-// _mobileNetClassifier.interpreter.address,
-// _mobileNetClassifier.labels,
-// ClassifierType.mobilenet,
-// );
-// return _getPredictions(isolateData);
-// } catch (e, s) {
-// _logger.severe("Could not run mobilenet", e, s);
-// }
-// return {};
-// }
-
-// Future<Map<String, double>> _getSceneResults(Uint8List bytes) async {
-// try {
-// final isolateData = IsolateData(
-// bytes,
-// _sceneClassifier.interpreter.address,
-// _sceneClassifier.labels,
-// ClassifierType.scenes,
-// );
-// return _getPredictions(isolateData);
-// } catch (e, s) {
-// _logger.severe("Could not run scene detection", e, s);
-// }
-// return {};
-// }
-
-// Future<Map<String, double>> _getPredictions(IsolateData isolateData) async {
-// final predictions = await _inference(isolateData);
-// final Map<String, double> results = {};
-
-// if (predictions.error == null) {
-// for (final Recognition result in predictions.recognitions!) {
-// if (result.score > scoreThreshold) {
-// // Update the result score only if it's higher than the current score
-// if (!results.containsKey(result.label) ||
-// results[result.label]! < result.score) {
-// results[result.label] = result.score;
-// }
-// }
-// }
-
-// _logger.info(
-// "Time taken for ${isolateData.type}: ${predictions.stats!.totalElapsedTime}ms",
-// );
-// } else {
-// _logger.severe(
-// "Error while fetching predictions for ${isolateData.type}",
-// predictions.error,
-// );
-// }
-
-// return results;
-// }
-
-// /// Runs inference in another isolate
-// Future<Predictions> _inference(IsolateData isolateData) async {
-// final responsePort = ReceivePort();
-// _isolateUtils.sendPort.send(
-// isolateData..responsePort = responsePort.sendPort,
-// );
-// return await responsePort.first;
-// }
-// }
diff --git a/mobile/lib/services/object_detection/tflite/classifier.dart b/mobile/lib/services/object_detection/tflite/classifier.dart
deleted file mode 100644
index 6a989b2792..0000000000
--- a/mobile/lib/services/object_detection/tflite/classifier.dart
+++ /dev/null
@@ -1,89 +0,0 @@
-// import "dart:math";
-
-// import 'package:image/image.dart' as image_lib;
-// import "package:logging/logging.dart";
-// import "package:photos/services/object_detection/models/predictions.dart";
-// import "package:tflite_flutter/tflite_flutter.dart";
-// import "package:tflite_flutter_helper/tflite_flutter_helper.dart";
-
-// abstract class Classifier {
-// // Path to the model
-// String get modelPath;
-
-// // Path to the labels
-// String get labelPath;
-
-// // Input size expected by the model (for eg. width = height = 224)
-// int get inputSize;
-
-// // Logger implementation for the specific classifier
-// Logger get logger;
-
-// Predictions? predict(image_lib.Image image);
-
-// /// Instance of Interpreter
-// late Interpreter _interpreter;
-
-// /// Labels file loaded as list
-// late List<String> _labels;
-
-// /// Shapes of output tensors
-// late List<List<int>> _outputShapes;
-
-// /// Types of output tensors
-// late List<TfLiteType> _outputTypes;
-
-// /// Gets the interpreter instance
-// Interpreter get interpreter => _interpreter;
-
-// /// Gets the loaded labels
-// List<String> get labels => _labels;
-
-// /// Gets the output shapes
-// List<List<int>> get outputShapes => _outputShapes;
-
-// /// Gets the output types
-// List<TfLiteType> get outputTypes => _outputTypes;
-
-// /// Loads interpreter from asset
-// void loadModel(Interpreter? interpreter) async {
-// try {
-// _interpreter = interpreter ??
-// await Interpreter.fromAsset(
-// modelPath,
-// options: InterpreterOptions()..threads = 4,
-// );
-// final outputTensors = _interpreter.getOutputTensors();
-// _outputShapes = [];
-// _outputTypes = [];
-// for (var tensor in outputTensors) {
-// _outputShapes.add(tensor.shape);
-// _outputTypes.add(tensor.type);
-// }
-// logger.info("Interpreter initialized");
-// } catch (e, s) {
-// logger.severe("Error while creating interpreter", e, s);
-// }
-// }
-
-// /// Loads labels from assets
-// void loadLabels(List<String>? labels) async {
-// try {
-// _labels = labels ?? await FileUtil.loadLabels(labelPath);
-// logger.info("Labels initialized");
-// } catch (e, s) {
-// logger.severe("Error while loading labels", e, s);
-// }
-// }
-
-// /// Pre-process the image
-// TensorImage getProcessedImage(TensorImage inputImage) {
-// final padSize = max(inputImage.height, inputImage.width);
-// final imageProcessor = ImageProcessorBuilder()
-// .add(ResizeWithCropOrPadOp(padSize, padSize))
-// .add(ResizeOp(inputSize, inputSize, ResizeMethod.BILINEAR))
-// .build();
-// inputImage = imageProcessor.process(inputImage);
-// return inputImage;
-// }
-// }
diff --git a/mobile/lib/services/object_detection/tflite/cocossd_classifier.dart b/mobile/lib/services/object_detection/tflite/cocossd_classifier.dart
deleted file mode 100644
index 246d704982..0000000000
--- a/mobile/lib/services/object_detection/tflite/cocossd_classifier.dart
+++ /dev/null
@@ -1,115 +0,0 @@
-// import 'dart:math';
-
-// import 'package:image/image.dart' as image_lib;
-// import "package:logging/logging.dart";
-// import 'package:photos/services/object_detection/models/predictions.dart';
-// import 'package:photos/services/object_detection/models/recognition.dart';
-// import "package:photos/services/object_detection/models/stats.dart";
-// import "package:photos/services/object_detection/tflite/classifier.dart";
-// import "package:tflite_flutter/tflite_flutter.dart";
-// import "package:tflite_flutter_helper/tflite_flutter_helper.dart";
-
-// /// Classifier
-// class CocoSSDClassifier extends Classifier {
-// static final _logger = Logger("CocoSSDClassifier");
-// static const double threshold = 0.4;
-
-// @override
-// String get modelPath => "models/cocossd/model.tflite";
-
-// @override
-// String get labelPath => "assets/models/cocossd/labels.txt";
-
-// @override
-// int get inputSize => 300;
-
-// @override
-// Logger get logger => _logger;
-
-// static const int numResults = 10;
-
-// CocoSSDClassifier({
-// Interpreter? interpreter,
-// List<String>? labels,
-// }) {
-// loadModel(interpreter);
-// loadLabels(labels);
-// }
-
-// @override
-// Predictions? predict(image_lib.Image image) {
-// final predictStartTime = DateTime.now().millisecondsSinceEpoch;
-
-// final preProcessStart = DateTime.now().millisecondsSinceEpoch;
-
-// // Create TensorImage from image
-// TensorImage inputImage = TensorImage.fromImage(image);
-
-// // Pre-process TensorImage
-// inputImage = getProcessedImage(inputImage);
-
-// final preProcessElapsedTime =
-// DateTime.now().millisecondsSinceEpoch - preProcessStart;
-
-// // TensorBuffers for output tensors
-// final outputLocations = TensorBufferFloat(outputShapes[0]);
-// final outputClasses = TensorBufferFloat(outputShapes[1]);
-// final outputScores = TensorBufferFloat(outputShapes[2]);
-// final numLocations = TensorBufferFloat(outputShapes[3]);
-
-// // Inputs object for runForMultipleInputs
-// // Use [TensorImage.buffer] or [TensorBuffer.buffer] to pass by reference
-// final inputs = [inputImage.buffer];
-
-// // Outputs map
-// final outputs = {
-// 0: outputLocations.buffer,
-// 1: outputClasses.buffer,
-// 2: outputScores.buffer,
-// 3: numLocations.buffer,
-// };
-
-// final inferenceTimeStart = DateTime.now().millisecondsSinceEpoch;
-
-// // run inference
-// interpreter.runForMultipleInputs(inputs, outputs);
-
-// final inferenceTimeElapsed =
-// DateTime.now().millisecondsSinceEpoch - inferenceTimeStart;
-
-// // Maximum number of results to show
-// final resultsCount = min(numResults, numLocations.getIntValue(0));
-
-// // Using labelOffset = 1 as ??? at index 0
-// const labelOffset = 1;
-
-// final recognitions = <Recognition>[];
-
-// for (int i = 0; i < resultsCount; i++) {
-// // Prediction score
-// final score = outputScores.getDoubleValue(i);
-
-// // Label string
-// final labelIndex = outputClasses.getIntValue(i) + labelOffset;
-// final label = labels.elementAt(labelIndex);
-
-// if (score > threshold) {
-// recognitions.add(
-// Recognition(i, label, score),
-// );
-// }
-// }
-
-// final predictElapsedTime =
-// DateTime.now().millisecondsSinceEpoch - predictStartTime;
-// return Predictions(
-// recognitions,
-// Stats(
-// predictElapsedTime,
-// predictElapsedTime,
-// inferenceTimeElapsed,
-// preProcessElapsedTime,
-// ),
-// );
-// }
-// }
diff --git a/mobile/lib/services/object_detection/tflite/mobilenet_classifier.dart b/mobile/lib/services/object_detection/tflite/mobilenet_classifier.dart
deleted file mode 100644
index d3cadd1a61..0000000000
--- a/mobile/lib/services/object_detection/tflite/mobilenet_classifier.dart
+++ /dev/null
@@ -1,83 +0,0 @@
-// import 'package:image/image.dart' as image_lib;
-// import "package:logging/logging.dart";
-// import 'package:photos/services/object_detection/models/predictions.dart';
-// import 'package:photos/services/object_detection/models/recognition.dart';
-// import "package:photos/services/object_detection/models/stats.dart";
-// import "package:photos/services/object_detection/tflite/classifier.dart";
-// import "package:tflite_flutter/tflite_flutter.dart";
-// import "package:tflite_flutter_helper/tflite_flutter_helper.dart";
-
-// // Source: https://tfhub.dev/tensorflow/lite-model/mobilenet_v1_1.0_224/1/default/1
-// class MobileNetClassifier extends Classifier {
-// static final _logger = Logger("MobileNetClassifier");
-// static const double threshold = 0.4;
-
-// @override
-// String get modelPath => "models/mobilenet/mobilenet_v1_1.0_224_quant.tflite";
-
-// @override
-// String get labelPath =>
-// "assets/models/mobilenet/labels_mobilenet_quant_v1_224.txt";
-
-// @override
-// int get inputSize => 224;
-
-// @override
-// Logger get logger => _logger;
-
-// MobileNetClassifier({
-// Interpreter? interpreter,
-// List<String>? labels,
-// }) {
-// loadModel(interpreter);
-// loadLabels(labels);
-// }
-
-// @override
-// Predictions? predict(image_lib.Image image) {
-// final predictStartTime = DateTime.now().millisecondsSinceEpoch;
-
-// final preProcessStart = DateTime.now().millisecondsSinceEpoch;
-
-// // Create TensorImage from image
-// TensorImage inputImage = TensorImage.fromImage(image);
-
-// // Pre-process TensorImage
-// inputImage = getProcessedImage(inputImage);
-
-// final preProcessElapsedTime =
-// DateTime.now().millisecondsSinceEpoch - preProcessStart;
-
-// // TensorBuffers for output tensors
-// final output = TensorBufferUint8(outputShapes[0]);
-// final inferenceTimeStart = DateTime.now().millisecondsSinceEpoch;
-// // run inference
-// interpreter.run(inputImage.buffer, output.buffer);
-
-// final inferenceTimeElapsed =
-// DateTime.now().millisecondsSinceEpoch - inferenceTimeStart;
-
-// final recognitions = <Recognition>[];
-// for (int i = 0; i < labels.length; i++) {
-// final score = output.getDoubleValue(i) / 255;
-// final label = labels.elementAt(i);
-// if (score >= threshold) {
-// recognitions.add(
-// Recognition(i, label, score),
-// );
-// }
-// }
-
-// final predictElapsedTime =
-// DateTime.now().millisecondsSinceEpoch - predictStartTime;
-// return Predictions(
-// recognitions,
-// Stats(
-// predictElapsedTime,
-// predictElapsedTime,
-// inferenceTimeElapsed,
-// preProcessElapsedTime,
-// ),
-// );
-// }
-// }
diff --git a/mobile/lib/services/object_detection/tflite/scene_classifier.dart b/mobile/lib/services/object_detection/tflite/scene_classifier.dart
deleted file mode 100644
index 1c1db6ce8f..0000000000
--- a/mobile/lib/services/object_detection/tflite/scene_classifier.dart
+++ /dev/null
@@ -1,88 +0,0 @@
-// import "package:flutter/foundation.dart";
-// import 'package:image/image.dart' as image_lib;
-// import "package:logging/logging.dart";
-// import 'package:photos/services/object_detection/models/predictions.dart';
-// import 'package:photos/services/object_detection/models/recognition.dart';
-// import "package:photos/services/object_detection/models/stats.dart";
-// import "package:photos/services/object_detection/tflite/classifier.dart";
-// import "package:tflite_flutter/tflite_flutter.dart";
-// import "package:tflite_flutter_helper/tflite_flutter_helper.dart";
-
-// // Source: https://tfhub.dev/sayannath/lite-model/image-scene/1
-// class SceneClassifier extends Classifier {
-// static final _logger = Logger("SceneClassifier");
-// static const double threshold = 0.35;
-
-// @override
-// String get modelPath => "models/scenes/model.tflite";
-
-// @override
-// String get labelPath => "assets/models/scenes/labels.txt";
-
-// @override
-// int get inputSize => 224;
-
-// @override
-// Logger get logger => _logger;
-
-// SceneClassifier({
-// Interpreter? interpreter,
-// List<String>? labels,
-// }) {
-// loadModel(interpreter);
-// loadLabels(labels);
-// }
-
-// @override
-// Predictions? predict(image_lib.Image image) {
-// final predictStartTime = DateTime.now().millisecondsSinceEpoch;
-
-// final preProcessStart = DateTime.now().millisecondsSinceEpoch;
-
-// // Create TensorImage from image
-// TensorImage inputImage = TensorImage.fromImage(image);
-
-// // Pre-process TensorImage
-// inputImage = getProcessedImage(inputImage);
-// final list = inputImage.getTensorBuffer().getDoubleList();
-// final input = list.reshape([1, inputSize, inputSize, 3]);
-
-// final preProcessElapsedTime =
-// DateTime.now().millisecondsSinceEpoch - preProcessStart;
-
-// final output = TensorBufferFloat(outputShapes[0]);
-
-// final inferenceTimeStart = DateTime.now().millisecondsSinceEpoch;
-// interpreter.run(input, output.buffer);
-// final inferenceTimeElapsed =
-// DateTime.now().millisecondsSinceEpoch - inferenceTimeStart;
-
-// final recognitions = <Recognition>[];
-// for (int i = 0; i < labels.length; i++) {
-// final score = output.getDoubleValue(i);
-// final label = labels.elementAt(i);
-// if (score >= threshold) {
-// recognitions.add(
-// Recognition(i, label, score),
-// );
-// } else if (kDebugMode && score > 0.2) {
-// debugPrint("scenePrediction score $label is below threshold: $score");
-// }
-// }
-// debugPrint(
-// "Total lables ${labels.length} + reccg ${recognitions.map((e) => e.label).toSet()}",
-// );
-
-// final predictElapsedTime =
-// DateTime.now().millisecondsSinceEpoch - predictStartTime;
-// return Predictions(
-// recognitions,
-// Stats(
-// predictElapsedTime,
-// predictElapsedTime,
-// inferenceTimeElapsed,
-// preProcessElapsedTime,
-// ),
-// );
-// }
-// }
diff --git a/mobile/lib/services/object_detection/utils/isolate_utils.dart b/mobile/lib/services/object_detection/utils/isolate_utils.dart
deleted file mode 100644
index c5c46e8636..0000000000
--- a/mobile/lib/services/object_detection/utils/isolate_utils.dart
+++ /dev/null
@@ -1,88 +0,0 @@
-// import 'dart:isolate';
-// import "dart:typed_data";
-
-// import 'package:image/image.dart' as imgLib;
-// import "package:photos/services/object_detection/models/predictions.dart";
-// import "package:photos/services/object_detection/tflite/classifier.dart";
-// import 'package:photos/services/object_detection/tflite/cocossd_classifier.dart';
-// import "package:photos/services/object_detection/tflite/mobilenet_classifier.dart";
-// import "package:photos/services/object_detection/tflite/scene_classifier.dart";
-// import 'package:tflite_flutter/tflite_flutter.dart';
-
-// /// Manages separate Isolate instance for inference
-// class IsolateUtils {
-// static const String debugName = "InferenceIsolate";
-
-// late SendPort _sendPort;
-// final _receivePort = ReceivePort();
-
-// SendPort get sendPort => _sendPort;
-
-// Future<void> start() async {
-// await Isolate.spawn<SendPort>(
-// entryPoint,
-// _receivePort.sendPort,
-// debugName: debugName,
-// );
-
-// _sendPort = await _receivePort.first;
-// }
-
-// static void entryPoint(SendPort sendPort) async {
-// final port = ReceivePort();
-// sendPort.send(port.sendPort);
-
-// await for (final IsolateData isolateData in port) {
-// final classifier = _getClassifier(isolateData);
-// final image = imgLib.decodeImage(isolateData.input);
-// try {
-// final results = classifier.predict(image!);
-// isolateData.responsePort.send(results);
-// } catch (e) {
-// isolateData.responsePort.send(Predictions(null, null, error: e));
-// }
-// }
-// }
-
-// static Classifier _getClassifier(IsolateData isolateData) {
-// final interpreter = Interpreter.fromAddress(isolateData.interpreterAddress);
-// if (isolateData.type == ClassifierType.cocossd) {
-// return CocoSSDClassifier(
-// interpreter: interpreter,
-// labels: isolateData.labels,
-// );
-// } else if (isolateData.type == ClassifierType.mobilenet) {
-// return MobileNetClassifier(
-// interpreter: interpreter,
-// labels: isolateData.labels,
-// );
-// } else {
-// return SceneClassifier(
-// interpreter: interpreter,
-// labels: isolateData.labels,
-// );
-// }
-// }
-// }
-
-// /// Bundles data to pass between Isolate
-// class IsolateData {
-// Uint8List input;
-// int interpreterAddress;
-// List<String> labels;
-// ClassifierType type;
-// late SendPort responsePort;
-
-// IsolateData(
-// this.input,
-// this.interpreterAddress,
-// this.labels,
-// this.type,
-// );
-// }
-
-// enum ClassifierType {
-// cocossd,
-// mobilenet,
-// scenes,
-// }