Skip to content

Commit

Permalink
Merge pull request #241 from mdejeans/fix_class_opaque
Browse files Browse the repository at this point in the history
fix: final class for tflite bindings
  • Loading branch information
PaulTR authored Sep 3, 2024
2 parents 83a2013 + 38e430a commit 351225d
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 119 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
```
2 changes: 1 addition & 1 deletion example/reinforcement_learning/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PlaneStrike extends StatefulWidget {

// This widget is the root of your application.
@override
_PlaneStrikeState createState() => _PlaneStrikeState();
State<PlaneStrike> createState() => _PlaneStrikeState();
}

class _PlaneStrikeState extends State<PlaneStrike> {
Expand Down
Loading

0 comments on commit 351225d

Please sign in to comment.