Skip to content

Commit

Permalink
fix dart format
Browse files Browse the repository at this point in the history
  • Loading branch information
duy-maimanh committed Feb 7, 2024
1 parent 55e04ba commit 8ec583f
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions lib/src/interpreter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import 'dart:ffi';
import 'dart:io';
import 'dart:collection';

import 'package:ffi/ffi.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -212,14 +211,10 @@ class Interpreter {
inputTensors.elementAt(i).setTo(inputs[i]);
}

var inferenceStartNanos = DateTime
.now()
.microsecondsSinceEpoch;
var inferenceStartNanos = DateTime.now().microsecondsSinceEpoch;
invoke();
_lastNativeInferenceDurationMicroSeconds =
DateTime
.now()
.microsecondsSinceEpoch - inferenceStartNanos;
DateTime.now().microsecondsSinceEpoch - inferenceStartNanos;
}

/// Gets all input tensors associated with the model.
Expand All @@ -230,9 +225,8 @@ class Interpreter {

var tensors = List.generate(
tfliteBinding.TfLiteInterpreterGetInputTensorCount(_interpreter),
(i) =>
Tensor(
tfliteBinding.TfLiteInterpreterGetInputTensor(_interpreter, i)),
(i) => Tensor(
tfliteBinding.TfLiteInterpreterGetInputTensor(_interpreter, i)),
growable: false);

return tensors;
Expand All @@ -246,10 +240,8 @@ class Interpreter {

var tensors = List.generate(
tfliteBinding.TfLiteInterpreterGetOutputTensorCount(_interpreter),
(i) =>
Tensor(
tfliteBinding.TfLiteInterpreterGetOutputTensor(
_interpreter, i)),
(i) => Tensor(
tfliteBinding.TfLiteInterpreterGetOutputTensor(_interpreter, i)),
growable: false);

return tensors;
Expand All @@ -260,7 +252,7 @@ class Interpreter {
final dimensionSize = shape.length;
final dimensions = calloc<Int>(dimensionSize);
final externalTypedData =
dimensions.cast<Int32>().asTypedList(dimensionSize);
dimensions.cast<Int32>().asTypedList(dimensionSize);
externalTypedData.setRange(0, dimensionSize, shape);
final status = tfliteBinding.TfLiteInterpreterResizeInputTensor(
_interpreter, tensorIndex, dimensions, dimensionSize);
Expand Down Expand Up @@ -348,7 +340,7 @@ class Interpreter {
// check if signature key exists
if (!_signatureRunners.containsKey(signatureKey)) {
Pointer<Char> signatureKeyPointer =
signatureKey.toNativeUtf8() as Pointer<Char>;
signatureKey.toNativeUtf8() as Pointer<Char>;
final signatureRunner = tfliteBinding.TfLiteInterpreterGetSignatureRunner(
_interpreter, signatureKeyPointer);
_signatureRunners[signatureKey] = signatureRunner;
Expand All @@ -362,23 +354,23 @@ class Interpreter {
int getSignatureInputCount(String signatureKey) {
final signatureRunner = _getSignatureRunner(signatureKey);
final subGraphIndex =
tfliteBinding.TfLiteSignatureRunnerGetInputCount(signatureRunner);
tfliteBinding.TfLiteSignatureRunnerGetInputCount(signatureRunner);
return subGraphIndex;
}

/// Get the number of outputs associated with a signature
int getSignatureOutputCount(String signatureKey) {
final signatureRunner = _getSignatureRunner(signatureKey);
final subGraphIndex =
tfliteBinding.TfLiteSignatureRunnerGetOutputCount(signatureRunner);
tfliteBinding.TfLiteSignatureRunnerGetOutputCount(signatureRunner);
return subGraphIndex;
}

/// Get input name by index and signature key.
String getSignatureInputName(String signatureKey, int index) {
final signatureRunner = _getSignatureRunner(signatureKey);
final inputName =
tfliteBinding.TfLiteSignatureRunnerGetInputName(signatureRunner, index);
tfliteBinding.TfLiteSignatureRunnerGetInputName(signatureRunner, index);
return inputName.cast<Utf8>().toDartString();
}

Expand All @@ -390,8 +382,8 @@ class Interpreter {
return outputName.cast<Utf8>().toDartString();
}

List<int> getSignatureInputTensorShape(String signatureKey,
String inputName) {
List<int> getSignatureInputTensorShape(
String signatureKey, String inputName) {
final signatureRunner = _getSignatureRunner(signatureKey);
final inputTensor = Tensor(
tfliteBinding.TfLiteSignatureRunnerGetInputTensor(
Expand All @@ -400,8 +392,8 @@ class Interpreter {
return shape;
}

List<int> getSignatureOutputTensorShape(String signatureKey,
String outputName) {
List<int> getSignatureOutputTensorShape(
String signatureKey, String outputName) {
final signatureRunner = _getSignatureRunner(signatureKey);
final outputTensor = Tensor(
tfliteBinding.TfLiteSignatureRunnerGetOutputTensor(
Expand All @@ -421,7 +413,7 @@ class Interpreter {
}

final Pointer<TfLiteSignatureRunner> signatureRunner =
_getSignatureRunner(signatureKey);
_getSignatureRunner(signatureKey);

inputs.forEach((key, value) {
Tensor inputTensor = Tensor(
Expand Down

0 comments on commit 8ec583f

Please sign in to comment.