mrousavy / react-native-fast-tflite

🔥 High-performance TensorFlow Lite library for React Native with GPU acceleration
https://mrousavy.com
MIT License
703 stars 33 forks source link

Clarification Needed on TensorFlow Lite Version and GPU Acceleration Configuration #83

Open bglgwyng opened 2 months ago

bglgwyng commented 2 months ago

Thank you for developing this excellent library. I've been using the native TensorFlow Lite library directly with Swift/Kotlin and am now migrating my code to use react-native-fast-tflite. Having experience configuring TensorFlow Lite, I have a couple of questions regarding the Android configuration:

  1. Version Selection: Why does this library use an older version of TensorFlow Lite (2.12.0) instead of the latest version (2.16.1)? Is there a specific reason for pinning to this older version?

  2. GPU Acceleration Configuration: I noticed that 'uses-native-library' declarations are required to enable GPU acceleration. While I understand their necessity (as GPU loading fails without them), I'm curious about why they're needed here when they weren't required in my previous direct TensorFlow Lite implementations.

For context, when I previously installed TensorFlow Lite directly, the following Gradle dependencies were sufficient for GPU acceleration:

implementation 'org.tensorflow:tensorflow-lite:2.15.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.15.0'
implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.15.0'

Is the need for these additional configurations related to the older TensorFlow Lite version (2.12.0) used in this library? Or am I missing something?

maintenance-hans[bot] commented 2 months ago

Guten Tag, Hans here! 🍻

Thank you for your kind words and for sponsoring the repo! Your questions are quite relevant.

  1. Regarding ze TensorFlow Lite version, mrousavy may be using an older version for compatibility reasons with react-native-fast-tflite. This helps ensure stability and avoids potential breaking changes. It's always good to check ze changelogs for updates.

  2. As for ze GPU acceleration configuration, differences can arise between library implementations and direct TensorFlow Lite usage. It's possible that our library requires additional declarations for proper initialization.

If you have further questions or specific logs related to issues while using this library, feel free to provide ze details, and we can investigate more!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

mrousavy commented 2 months ago

Hey @bglgwyng - thank you for the kind words.

Well, to be honest I don't have an answer to your questions. I built this library a while ago fairly quickly, and I didn't investigate GPU delegates any further. It worked, but I didn't use this library for any of my RN apps. I know a lot of people use react-native-fast-tflite (and even a lot of my clients use it), but I haven't done any significant changes here since it's release.

I'd appreciate it if you find answers to those questions after just trying stuff out, maybe we can bump the version to latest, and maybe we can simplify the GPU delegate. PRs of course welcome!

Thanks!

mrousavy commented 2 months ago

iirc I tried to integrate TFLite by source, to avoid having to depend on a pod or gradle input. By source was a bit too complicated because I couldn't get it to build. That would've also worked with Simulators, and is a shared C++ codebase. I haven't pursued this further, but would be cool if you could get that working

bglgwyng commented 2 months ago

@TkTioNG Hello! I found that you are the author of this PR Here I asked some questions related to the PR, could you please provide answers for them?

TkTioNG commented 2 months ago

@bglgwyng Hi!

OpenCL is not necessarily compulsory to enable GPU acceleration. May be you can try to compile your app without using it? I believe that without using OpenCL, the device will try to use the default graphics api instead (I cannot guarantee you with that XD)

Just that some of the tflite model operations, and some configurations (like serialization) will need OpenCL, where the default graphics api cannot provide and will failed to be initialized.

bglgwyng commented 2 months ago

@TkTioNG Thanks for the brief reply! What about the version? Do you think it is ok to bump it up?

mrousavy commented 2 months ago

https://github.com/mrousavy/react-native-fast-tflite/pull/85