Use GPU Delegates on Android (GPU/NNAPI)
mainTo enable GPU or NNAPI acceleration on Android, you may need to include native libraries.
Expo
Use the config plugin in app.json or app.config.js. You can enable default libraries or specify an array of specific .so files:
{
"name": "my app",
"plugins": [
[
"react-native-fast-tflite",
{
"enableAndroidGpuLibraries": true
}
]
]
}Or for specific libraries:
{
"name": "my app",
"plugins": [
[
"react-native-fast-tflite",
{
"enableAndroidGpuLibraries": ["libOpenCL-pixel.so", "libGLES_mali.so"]
}
]
]
}Bare React Native
Add the required libraries to your AndroidManifest.xml:
<uses-native-library android:name="libOpenCL.so" android:required="false" />
<uses-native-library android:name="libOpenCL-pixel.so" android:required="false" />
<uses-native-library android:name="libGLES_mali.so" android:required="false" />
<uses-native-library android:name="libPVROCL.so" android:required="false" />Usage
Pass ['android-gpu'] or ['nnapi'] to loadTensorflowModel:
// Use GPU delegate
const model = await loadTensorflowModel(
require('assets/my-model.tflite'),
['android-gpu']
)
// Use NNAPI delegate (Note: NNAPI is deprecated on Android 15; GPU is preferred)
const model = await loadTensorflowModel(
require('assets/my-model.tflite'),
['nnapi']
)const model = await loadTensorflowModel(
require('assets/my-model.tflite'),
['android-gpu']
)