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

TFLite platform libraries (binary vs. repository) #110

Open
mspnr opened this issue Apr 24, 2021 · 4 comments
Open

TFLite platform libraries (binary vs. repository) #110

mspnr opened this issue Apr 24, 2021 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@mspnr
Copy link

mspnr commented Apr 24, 2021

Confusion

After some experiments I can say that the location of the binary libraries on using tflite_flutter_plugin is confusing:

  • Libraries for Android are located in the project directory: <project dir>/android/app/src/main/jniLibs/arm64-v8a/libtensorflowlite_c.so
  • Libraries for iOS are located in Flutter directory: <flutter>/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-0.5.0/ios/TensorFlowLiteC.framework/TensorFlowLiteC
  • It is not clear where to get the libraries. There are multiple places:
    • You can download them from releases. Which version do you need? Can you trust them etc.
    • You can build them by yourself. Here are some hint for Android and for iOS. Also need some experience and consideration.

Here are some suggestions how the situation can be improved:

Suggestion 1

  • Place the binary libraries for both Android and iOS into the same place: either to the plugin library or to the project library
  • Provide a clear description how to update them to a stable or to the latest version

The first approach is flexible, by requires some experience from the developer building to libraries or at least to find the right place, where to put them. Also required to bring binaries.

Suggestion 2

Even better as suggested here #103 include libraries for the appropriate repository for each platform:

Android

Use Maven repository as a source of libraries for Android and include it to build.gradle (like here):

dependencies {
    implementation 'org.tensorflow:tensorflow-lite:2.4.0'
    implementation 'org.tensorflow:tensorflow-lite-gpu:2.4.0'
}

A good start point how to use it is here.

iOS

Use Cocoapods repository as a source of libraries for iOS and includr them to Podfile (like here):

pod 'TensorFlowLiteSwift', '~> 2.4.0', :subspecs => ['CoreML', 'Metal']

A possible start point can be here.

The second approach looks more appropriate as does not need to compile the libraries or bring binaries and it assumed as a best practice solution for the both platforms.
To switch the libraries between stable and experimental version it is only needed to change versions of the libraries in build.gradle or Podfile.

@am15h
Copy link
Owner

am15h commented Apr 25, 2021

Thanks a lot for the analysis @applikationsprogramvara.

When using:

dependencies {
    implementation 'org.tensorflow:tensorflow-lite:2.4.0'
    implementation 'org.tensorflow:tensorflow-lite-gpu:2.4.0'
}

In the build directory, these two files are obtained separtely.

/build/app/intermediates/merged_native_libs/debug/out/lib/arm64-v8a/libtensorflowlite_jni.so
/build/app/intermediates/merged_native_libs/debug/out/lib/arm64-v8a/libtensorflowlite_gpu_jni.so

We can either load them sepeately or possibly host libtensorflowlite_normal_with_gpu.so on a new maven repository, so that everything becomes a zero setup process for the users of this plugin.

It would be helpful to get more information regarding how everything would work for the iOS counterpart pod 'TensorFlowLiteSwift', '~> 2.4.0', :subspecs => ['CoreML', 'Metal']

@lucyllewy
Copy link

lucyllewy commented Jan 23, 2022

For iOS to use cocoapods to download the library/frameowrk automatically, you would replace (in ios/tflite_flutter.podspec):

s.ios.vendored_frameworks = 'TensorFlowLiteC.framework'

with

s.dependency 'TensorFlowLiteC'

And optionally also include the coreml and metal delegates with:

s.dependency 'TensorFlowLiteC/Metal'
s.dependency 'TensorFlowLiteC/CoreML'

Or add all in one go (edit: I think this might not work, and requires Metal and CoreML as above?):

s.dependency 'TensorFlowLiteC', :subspecs => ['CoreML', 'Metal']

You can add version pinning with:

s.dependency 'TensorFlowLiteC', '~> 2.4.0'
s.dependency 'TensorFlowLiteC/Metal', '~> 2.4.0'
s.dependency 'TensorFlowLiteC/CoreML', '~> 2.4.0'

@am15h am15h added the documentation Improvements or additions to documentation label Mar 6, 2022
@CaptainDario
Copy link

CaptainDario commented Mar 7, 2022

@am15h not needing to use the install.bat and the complicated setup for iOS would be very nice.
Especially if this setup enables the metal/CoreML delegate for iOS would work.

Therefore could you please comment on how to use this setup procedure?

@BytesZero
Copy link

I changed both iOS and Android to remote dependencies:

tflite_flutter:
    git:
      url: git@github.com:yy1300326388/tflite_flutter_plugin.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants