Skip to content

Commit

Permalink
Merge pull request #87 from CaptainDario/feature-macos_support
Browse files Browse the repository at this point in the history
[Desktop] MacOS support
  • Loading branch information
PaulTR authored Sep 27, 2023
2 parents 15a1954 + 4c8b65a commit 22cdbdd
Show file tree
Hide file tree
Showing 229 changed files with 11,326 additions and 189 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ website/build

npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn-error.log*

# desktop binaries
**/blobs/*
!**/blobs/.gitkeep

# models
example/object_detection_ssd_mobilenet/assets/models/labelmap.txt
example/object_detection_ssd_mobilenet/assets/models/ssd_mobilenet.tflite
36 changes: 36 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
channel: stable

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
- platform: android
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
- platform: ios
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
- platform: macos
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ When creating a release archive (IPA), the symbols are stripped by Xcode, so the
1. In Xcode, go to **Target Runner > Build Settings > Strip Style**
2. Change from **All Symbols** to **Non-Global Symbols**

### MacOS

For MacOS a TensorFlow Lite dynamic library needs to be added to the project manually.
For this, first a `.dylib` needs to be built. You can follow the [Bazel build guide](https://www.tensorflow.org/lite/guide/build_arm) or the [CMake build guide](https://www.tensorflow.org/lite/guide/build_cmake) to build the libraries.

**CMake Note:**

- cross compiling in CMake can be achieved using:
`-DCMAKE_OSX_ARCHITECTURES=x86_64|arm64`

- bundling two architectures (arm / x86) using lipo:
`lipo -create arm64/libtensorflowlite_c.dylib x86/libtensorflowlite_c.dylib -output libtensorflowlite_c.dylib`

As a second step, the library needs to be added to your application's XCode project. For this, you can follow the step 1 and 2 of the [official Flutter guide on adding dynamic libraries](https://docs.flutter.dev/platform-integration/macos/c-interop#compiled-dynamic-library-macos).

## 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.tensorflow.tflite_flutter

import androidx.annotation.NonNull

import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result

/** TfliteFlutterPlugin */
class TfliteFlutterPlugin: FlutterPlugin, MethodCallHandler {
/// The MethodChannel that will the communication between Flutter and native Android
///
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
/// when the Flutter Engine is detached from the Activity
private lateinit var channel : MethodChannel

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "tflite_flutter")
channel.setMethodCallHandler(this)
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
if (call.method == "getPlatformVersion") {
result.success("Android ${android.os.Build.VERSION.RELEASE}")
} else {
result.notImplemented()
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.tensorflow.tflite_flutter

import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import kotlin.test.Test
import org.mockito.Mockito

/*
* This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation.
*
* Once you have built the plugin's example app, you can run these tests from the command
* line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or
* you can run them directly from IDEs that support JUnit such as Android Studio.
*/

internal class TfliteFlutterPluginTest {
@Test
fun onMethodCall_getPlatformVersion_returnsExpectedValue() {
val plugin = TfliteFlutterPlugin()

val call = MethodCall("getPlatformVersion", null)
val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java)
plugin.onMethodCall(call, mockResult)

Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE)
}
}
15 changes: 6 additions & 9 deletions example/audio_classification/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled.

version:
revision: 796c8ef79279f9c774545b3771238c3098dbefab
revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
channel: stable

project_type: app
Expand All @@ -13,14 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: android
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
- platform: ios
create_revision: 796c8ef79279f9c774545b3771238c3098dbefab
base_revision: 796c8ef79279f9c774545b3771238c3098dbefab
create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
- platform: macos
create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8

# User provided section

Expand Down
6 changes: 5 additions & 1 deletion example/audio_classification/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Audio classification Yamnet

| | Android | iOS | Linux | Mac | Windows | Web |
|------|---------|-----|-------|-----|---------|-----|
| live ||| | | | |

This project is a sample of how to perform Audio Classification using
TensorFlow Lite in Flutter. It includes support for both Android and IOS.

Expand All @@ -16,7 +20,7 @@ running `sh ./scripts/download_model.sh` from the root folder of the repository.
- Before building, ensure that you have downloaded the model and the labels by
following a set of instructions.

#### Screenshot
## Screenshots

![Android](screenshots/android_screenshot.png)

Expand Down
Binary file not shown.
Loading

0 comments on commit 22cdbdd

Please sign in to comment.