Skip to content

Commit 037a6eb

Browse files
authored
Merge pull request #30 from am15h/v0.5.0
v0.5.0
2 parents 4834414 + bb6a3b5 commit 037a6eb

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.0 (Jul 17, 2020)
2+
* Expose interpreter's address
3+
* Create interpreter by address.
4+
15
## 0.4.2 (Jul 6, 2020)
26
* Optimize getTensors and getTensor by Index
37
* Update readme

example/test/tflite_flutter_plugin_example_e2e.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:io';
6+
import 'dart:isolate';
67
import 'dart:typed_data';
78

89
import 'package:flutter/services.dart';
@@ -20,6 +21,7 @@ final int64FileName = 'int64.bin';
2021
final multiInputFileName = 'multi_add.bin';
2122
final addFileName = 'add.bin';
2223

24+
//flutter drive --driver=test_driver/tflite_flutter_plugin_example_e2e_test.dart test/tflite_flutter_plugin_example_e2e.dart
2325
void main() {
2426
E2EWidgetsFlutterBinding.ensureInitialized();
2527

@@ -45,6 +47,13 @@ void main() {
4547
interpreter.close();
4648
});
4749

50+
test('interpreter from address', () async {
51+
final interpreter = await tfl.Interpreter.fromAsset('test/$dataFileName');
52+
final interpreter2 = tfl.Interpreter.fromAddress(interpreter.address);
53+
interpreter.close();
54+
interpreter2.close();
55+
});
56+
4857
group('interpreter options', () {
4958
test('default', () async {
5059
final dataFile = await getFile(dataFileName);

lib/src/interpreter.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ class Interpreter {
127127
return rawBytes;
128128
}
129129

130+
/// Creates interpreter from an address.
131+
///
132+
/// Typically used for passing interpreter between isolates.
133+
factory Interpreter.fromAddress(int address,
134+
{bool allocated: false, bool deleted: false}) {
135+
final interpreter = Pointer<TfLiteInterpreter>.fromAddress(address);
136+
return Interpreter._(interpreter)
137+
.._deleted = deleted
138+
.._allocated = allocated;
139+
}
140+
130141
/// Destroys the interpreter instance.
131142
void close() {
132143
checkState(!_deleted, message: 'Interpreter already deleted.');
@@ -295,6 +306,13 @@ class Interpreter {
295306
}
296307
}
297308

309+
/// Returns the address to the interpreter
310+
int get address => _interpreter.address;
311+
312+
bool get isAllocated => _allocated;
313+
314+
bool get isDeleted => _deleted;
315+
298316
//TODO: (JAVA) void modifyGraphWithDelegate(Delegate delegate)
299317
//TODO: (JAVA) void resetVariableTensors()
300318

pubspec.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: tflite_flutter
22
description: TensorFlow Lite Flutter plugin provides easy, flexible and fast Dart API to integrate TFLite models in flutter apps.
3-
version: 0.4.2
3+
version: 0.5.0
44
homepage: https://github.com/am15h/tflite_flutter_plugin
55

66
environment:
77
sdk: ">=2.6.0 <3.0.0"
8+
flutter: ">=1.12.0 <2.0.0"
89

910
dependencies:
1011
flutter:
@@ -29,8 +30,12 @@ flutter:
2930
# be modified. They are used by the tooling to maintain consistency when
3031
# adding or updating assets for this project.
3132
plugin:
32-
androidPackage: com.tfliteflutter.tflite_flutter_plugin
33-
pluginClass: TfliteFlutterPlugin
33+
platforms:
34+
android:
35+
package: com.tfliteflutter.tflite_flutter_plugin
36+
pluginClass: TfliteFlutterPlugin
37+
ios:
38+
pluginClass: TfliteFlutterPlugin
3439

3540
# To add assets to your plugin package, add an assets section, like this:
3641
# assets:

0 commit comments

Comments
 (0)