You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TensorFlow Lite plugin provides a dart API for accessing TensorFlow Lite interpreter and performing inference. It binds to TensorFlow Lite C API using dart:ffi.
3
+
TensorFlow Lite plugin provides a dart API for accessing TensorFlow Lite interpreter and performing inference. It binds to TensorFlow Lite C API using dart:ffi.
6
4
7
-
## (Most Important) Initial setup
5
+
## (Important) Initial setup
8
6
9
-
####Add dynamic libraries to your app
7
+
### Add dynamic libraries to your app
10
8
11
9
***Linux/Mac Users**
12
10
13
-
Place the script [install.sh](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.sh) at the root of your project.
14
-
15
-
Execute <pre>sh [install.sh](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.sh)</pre> at the root of your project to automatically download and place binaries at appropriate folders.
11
+
Place the script [install.sh](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.sh) at the root of your project.
16
12
17
-
*The binaries installed will **not** include support for `GpuDelegateV2` and `NnApiDelegate` however `InterpreterOptions().useNnApiForAndroid` can still be used.*
13
+
Execute <pre>sh [install.sh](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.sh)</pre> at the root of your project to automatically download and place binaries at appropriate folders.
18
14
19
-
Use **`install.sh -d`** instead if you wish to use these `GpuDelegateV2` and `NnApiDelegate`.
15
+
*The binaries installed will **not** include support for`GpuDelegateV2` and `NnApiDelegate` however `InterpreterOptions().useNnApiForAndroid` can still be used.*
20
16
21
-
***Windows users**
17
+
Use **`install.sh -d`**instead if you wish to use these `GpuDelegateV2` and `NnApiDelegate`.
22
18
23
-
Place the script [install.bat](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.bat) at the root of your project.
19
+
***Windows users**
24
20
25
-
Execute <pre>[install.bat](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.bat)</pre> at the root of your project to automatically download and place binaries at appropriate folders.
21
+
Place the script [install.bat](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.bat) at the root of your project.
26
22
27
-
If you want to use delegate support then execute **`install.bat -d`**.
23
+
Execute <pre>[install.bat](https://github.com/am15h/tflite_flutter_plugin/blob/master/install.bat)</pre> at the root of your project to automatically download and place binaries at appropriate folders.
28
24
29
-
These scripts install pre-built binaries based on latest stable tensorflow release.
25
+
If you want to use delegate support then execute **`install.bat -d`**.
30
26
27
+
These scripts install pre-built binaries based on latest stable tensorflow release.
31
28
32
-
#### Why do we need to do this?
29
+
For info about using other tensorflow versions refer to [this](#use-the-plugin-with-any-tensorflow-version) part of readme.
33
30
34
-
`tflite_flutter` dynamically links to C APIs which are supplied in the form of `libtensorflowlite_c.so` on Android and `TensorFlowLiteC.framework` on iOS.
35
-
36
-
For Android, We need to manually download these binaries from release assets and place the libtensorflowlite_c.so files in the `<root>/android/app/src/main/jniLibs/` directory for each arm, arm64, x86, x86_64 architecture as done here in the example app.
31
+
## Import
37
32
38
-
No setup needed for iOS as of now, `TensorFlowLiteC.framework` is embedded in the plugin itself.
The pre-built binaries are updated with each stable tensorflow release. However, you many want to use latest unstable tf releases or older tf versions, for that proceed to build locally, if you are unable to find the required version in [release assets](https://github.com/am15h/tflite_flutter_plugin/releases).
37
+
### Creating the Interpreter
43
38
44
-
Make sure you have required version of bazel installed. (Check TF_MIN_BAZEL_VERSION, TF_MAX_BAZEL_VERSION in configure.py)
39
+
***From asset**
45
40
46
-
***Android**
41
+
Place `your_model.tflite` in `assets` directory. Make sure to include assets in `pubspec.yaml`.
47
42
48
-
Configure your workspace for android builds as per [these instructions](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/guide/android.md#configure-workspace-and-bazelrc).
43
+
```dart
44
+
final interpreter = await tfl.Interpreter.fromAsset('your_model.tflite');
var interpreterOptions = InterpreterOptions()..addDelegate(gpuDelegate);
216
148
final interpreter = await Interpreter.fromAsset('your_model.tflite',
217
149
options: interpreterOptions);
218
-
219
150
```
220
151
221
-
222
152
Refer [Tests](https://github.com/am15h/tflite_flutter_plugin/blob/master/example/test/tflite_flutter_plugin_example_e2e.dart) to see more example code for each method.
223
153
224
154
Refer [Text Classification Flutter Example App](https://github.com/am15h/tflite_flutter_plugin/tree/master/example) for demo.
225
155
156
+
#### Use the plugin with any tensorflow version
157
+
158
+
The pre-built binaries are updated with each stable tensorflow release. However, you many want to use latest unstable tf releases or older tf versions, for that proceed to build locally, if you are unable to find the required version in [release assets](https://github.com/am15h/tflite_flutter_plugin/releases).
159
+
160
+
Make sure you have required version of bazel installed. (Check TF_MIN_BAZEL_VERSION, TF_MAX_BAZEL_VERSION in configure.py)
161
+
162
+
* **Android**
163
+
164
+
Configure your workspace for android builds as per [these instructions](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/guide/android.md#configure-workspace-and-bazelrc).
// similarily for arm64 use --config=android_arm64
179
+
```
180
+
181
+
* **iOS**
182
+
183
+
Refer [instructions on TensorFlow Lite website](https://www.tensorflow.org/lite/guide/build_ios#install_bazel) to build locally for iOS.
184
+
185
+
Note: You must use macOS for building iOS.
186
+
187
+
#### More info on dynamic linking
188
+
189
+
`tflite_flutter` dynamically links to C APIs which are supplied in the form of `libtensorflowlite_c.so` on Android and `TensorFlowLiteC.framework` on iOS.
190
+
191
+
For Android, We need to manually download these binaries from release assets and place the libtensorflowlite_c.so files in the `<root>/android/app/src/main/jniLibs/` directory for each arm, arm64, x86, x86_64 architecture as done here in the example app.
192
+
193
+
No setup needed for iOS as of now, `TensorFlowLiteC.framework` is embedded in the plugin itself.
194
+
226
195
## Credits
227
196
228
197
* Tian LIN, Jared Duke, Andrew Selle, YoungSeok Yoon, Shuangfeng Li from the TensorFlow Lite Team for their invaluable guidance.
229
-
* Authors of [dart-lang/tflite_native](https://github.com/dart-lang/tflite_native).
198
+
* Authors of [dart-lang/tflite_native](https://github.com/dart-lang/tflite_native).
0 commit comments