-
-
Notifications
You must be signed in to change notification settings - Fork 65
Description
Today, we build TensorFlowLiteC from source to use it in iOS:
react-native-fast-tflite/scripts/build-tensorflow-ios.sh
Lines 13 to 27 in 5b8d612
# Assumes the user ran ./configure in tensorflow/ already | |
cd tensorflow | |
bazel build --config=ios_fat -c opt --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteC_framework | |
bazel build --config=ios_fat -c opt --cxxopt=--std=c++17 //tensorflow/lite/ios:TensorFlowLiteCCoreML_framework | |
cd .. | |
cp -f -r tensorflow/bazel-bin/tensorflow/lite/ios/ ios/ | |
unzip -o ios/TensorFlowLiteC_framework.zip -d ios | |
rm ios/TensorFlowLiteC_framework.zip | |
unzip -o ios/TensorFlowLiteCCoreML_framework.zip -d ios | |
rm ios/TensorFlowLiteCCoreML_framework.zip |
The source code is added to this repo as a git submodule (tensorflow/
), and when shipping the library to npm I prebuild a TensorFlowLiteC binary (including the TensorFlowLiteCCoreML delegate), add the headers, then ship it.
On Android however, we use the org.tensorflow:tensorflow-lite
library from Gradle:
react-native-fast-tflite/android/build.gradle
Lines 125 to 128 in 5b8d612
// Tensorflow Lite .aar (includes C API via prefabs) | |
implementation "org.tensorflow:tensorflow-lite:2.12.0" | |
extractHeaders("org.tensorflow:tensorflow-lite:2.12.0") | |
extractSO("org.tensorflow:tensorflow-lite:2.12.0") |
This ships the Java files as well as introducing some other unnecessary files for the bundle. Also, it is outdated and not in sync with the iOS version, some fixes, features or improvements may only be available on iOS, but not on Android due to us using the published package from Maven. (Currently we use v2.2.0, which is outdated by more than two versions)
Instead, we should aim to also use TensorFlowLiteC (any potentially also an Android GPU delegate?) from source by also building it in the tensorflow/
submodule, just like how we do it on iOS, then add the headers and link the library in the android/CMakeLists.txt
config.
This would align the versions perfectly and we don't need to fetch a prebuild version from Maven.
This PR was an attempt at doing so: #33 ...but I couldn't manage to get Bazel to build the Android version.
We need to make sure this ships the correct binaries (x86, x86_64, arm, and arm64 - or just x86_fat and arm_fat).
Added Bonus: Maybe we can even do the whole building in the CI with dependabot, so everytime the submodule changes (a commit lands on main in tensorflow/
) it opens a PR, prebuilds the libraries, moves them into ios
and android
, and I only need to merge that to get the changes. No need to build it on my mac. Makes it even more safe