adding some basic linting - prepping support for multiple models being loaded in by the app.

This commit is contained in:
Lucas Oskorep
2022-07-08 18:30:25 -04:00
parent b8119e6520
commit 284fa4a2f8
13 changed files with 99 additions and 54 deletions
+16
View File
@@ -0,0 +1,16 @@
import 'package:tflite_flutter/tflite_flutter.dart';
import 'constants.dart';
class ModelConfiguration{
String name;
late List<InterpreterOptions> interpreters;
ModelConfiguration(this.name){
interpreters = name.contains('gpu') ? ModelConstants.gpuInterpreterList : ModelConstants.cpuInterpreterList;
}
@override
String toString() {
return 'ModelConfiguration(name: $name, interpreters: $interpreters)';
}
}
+10
View File
@@ -0,0 +1,10 @@
import 'package:tflite_flutter/tflite_flutter.dart';
class ModelConstants {
static final InterpreterOptions _npuConfig = InterpreterOptions()..threads = 8..useNnApiForAndroid = true..useMetalDelegateForIOS = true;
static final InterpreterOptions _cpuConfig = InterpreterOptions()..threads = 8;
static final List<InterpreterOptions> gpuInterpreterList = [_npuConfig, _cpuConfig];
static final List<InterpreterOptions> cpuInterpreterList = [_cpuConfig];
}
+21
View File
@@ -0,0 +1,21 @@
/// 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);
int get id => _id;
String get label => _label;
double get score => _score;
@override
String toString() {
return 'Recognition(id: $id, label: $label, score: $score)';
}
}
+18
View File
@@ -0,0 +1,18 @@
class Stats {
int totalTime;
int preProcessingTime;
int inferenceTime;
int postProcessingTime;
Stats(
{this.totalTime = -1,
this.preProcessingTime = -1,
this.inferenceTime = -1,
this.postProcessingTime = -1});
@override
String toString() {
return 'Stats{totalPredictTime: $totalTime, preProcessingTime: $preProcessingTime, inferenceTime: $inferenceTime, postProcessingTime: $postProcessingTime}';
}
}