tflite_flutter_plugin icon indicating copy to clipboard operation
tflite_flutter_plugin copied to clipboard

TFLite platform libraries (binary vs. repository)

Open mspnr opened this issue 3 years ago • 4 comments

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.

mspnr avatar Apr 24 '21 00:04 mspnr