margelo / margelo/react-native-fast-tflite
Use TensorFlowLiteC from source (`tensorflow/`) on Android as well
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 92
- Avg merge
- 13h 9m
- Merged PRs (30d)
- 2
Description
Today, we build TensorFlowLiteC from source to use it in iOS: https://github.com/mrousavy/react-native-fast-tflite/blob/5b8d61270e777dd5b66bbe06004e5109bac8f874/scripts/build-tensorflow-ios.sh#L13-L27
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: https://github.com/mrousavy/react-native-fast-tflite/blob/5b8d61270e777dd5b66bbe06004e5109bac8f874/android/build.gradle#L125-L128
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: https://github.com/mrousavy/react-native-fast-tflite/pull/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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with scripts/build-tensorflow-ios.sh, android/build.gradle, android/CMakeLists.txt, and the TensorFlow submodule; review pull request #33 for the unsuccessful Android build attempt. Investigate building TensorFlowLiteC from source and linking it through CMake instead of Maven. Done means shipping correct x86, x86_64, arm, and arm64 Android binaries aligned with iOS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, react-native, tensorflow
- Domain
- build-system, machine-learning, mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100