Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: final class for tflite bindings #241

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
```
Loading
Loading