Skip to content

Commit

Permalink
chore(melos): update readme and add melos for FFI code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Dejean-Servieres committed Sep 2, 2024
1 parent 8101f95 commit be97988
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</br>
</p>
<p align="center">

<a href="https://flutter.dev">
<img src="https://img.shields.io/badge/Platform-Flutter-02569B?logo=flutter"
alt="Platform" />
Expand All @@ -18,7 +18,6 @@
</a>
<a href="https://opensource.org/licenses/Apache-2.0"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a>


</a>
</p>

Expand All @@ -40,16 +39,14 @@ Thanks!

TensorFlow Lite Flutter plugin provides a flexible and fast solution for accessing TensorFlow Lite interpreter and performing inference. The API is similar to the TFLite Java and Swift APIs. It directly binds to TFLite C API making it efficient (low-latency). Offers acceleration support using NNAPI, GPU delegates on Android, Metal and CoreML delegates on iOS, and XNNPack delegate on Desktop platforms.


## Key Features

* Multi-platform Support for Android and iOS
* Flexibility to use any TFLite Model.
* Acceleration using multi-threading.
* Similar structure as TensorFlow Lite Java API.
* Inference speeds close to native Android Apps built using the Java API.
* Run inference in different isolates to prevent jank in UI thread.

- Multi-platform Support for Android and iOS
- Flexibility to use any TFLite Model.
- Acceleration using multi-threading.
- Similar structure as TensorFlow Lite Java API.
- Inference speeds close to native Android Apps built using the Java API.
- Run inference in different isolates to prevent jank in UI thread.

## (Important) Initial setup : Add dynamic libraries to your app

Expand Down Expand Up @@ -133,7 +130,7 @@ install(

## TFLite Flutter Helper Library

The helper library has been deprecated. New development underway for a replacement at https://github.com/google/flutter-mediapipe. Current timeline is to have wide support by the end of August, 2023.
The helper library has been deprecated. New development underway for a replacement at <https://github.com/google/flutter-mediapipe>. Current timeline is to have wide support by the end of August, 2023.

## Import

Expand All @@ -144,11 +141,12 @@ import 'package:tflite_flutter/tflite_flutter.dart';
## Usage instructions

### Import the libraries

In the dependency section of `pubspec.yaml` file, add `tflite_flutter: ^0.10.1` (adjust the version accordingly based on the latest release)

### Creating the Interpreter

* **From asset**
- **From asset**

Place `your_model.tflite` in `assets` directory. Make sure to include assets in `pubspec.yaml`.

Expand All @@ -160,9 +158,10 @@ Refer to the documentation for info on creating interpreter from buffer or file.
### Performing inference
* **For single input and output**
- **For single input and output**
Use `void run(Object input, Object output)`.
```dart
// For ex: if input tensor shape [1,5] and type is float32
var input = [[1.23, 6.54, 7.81, 3.21, 2.22]];
Expand All @@ -177,7 +176,7 @@ Refer to the documentation for info on creating interpreter from buffer or file.
print(output);
```
* **For multiple inputs and outputs**
- **For multiple inputs and outputs**
Use `void runForMultipleInputs(List<Object> inputs, Map<int, Object> outputs)`.
Expand Down Expand Up @@ -225,3 +224,20 @@ await isolateInterpreter.runForMultipleInputs(inputs, outputs);
```

By using `IsolateInterpreter`, the inference runs in a separate isolate. This ensures that the main isolate, responsible for UI tasks, remains unblocked and responsive.

## Contribute to this package

This package is managed using [melos](https://pub.dev/packages/melos). Before starting to work on the project, make sure to run the bootstrap command.

```sh
dart pub global activate melos # Install or activate melos globally
melos bootstrap # Initialize the workspace and bootstrap the package
```

### Generated code

This package uses [ffigen](https://pub.dev/packages/ffigen) to generate FFI bindings. To run code generation, you can use the following melos command:

```sh
melos run ffigen
```
6 changes: 6 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ command:
branch: main
linkToCommits: true
workspaceChangelog: true

scripts:
ffigen:
name: ffigen
description: Call ffigen and generate bindings for `src/tensorflow_lite/c_api.h`.
run: flutter pub run ffigen --config ffigen_tensorflow_lite.yaml

0 comments on commit be97988

Please sign in to comment.