Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ return <Camera device="back" isActive={true} outputs={[frameOutput]} {...otherPr
> [!NOTE]
> Unlike v4, VisionCamera v5 no longer requires boxing the model with `NitroModules.box()`. Since v5 is built on Nitro Modules and uses [react-native-worklets](https://docs.swmansion.com/react-native-worklets/), worklets can access HybridObjects like the TFLite model directly.

### Using Android XNNPACK CPU Delegate

Pass `['xnnpack']` to opt into the Android XNNPACK CPU delegate:

```ts
const model = await loadTensorflowModel(require('assets/my-model.tflite'), [
'xnnpack',
])
```

Passing `[]` keeps the standard TFLite CPU path. XNNPACK is Android-only, uses an internally selected thread count capped for mobile devices, and cannot currently be combined with `android-gpu` or `nnapi`.

Use XNNPACK when CPU inference is the right fit for your model or when GPU/NNAPI is unavailable or slower on your target devices. Benchmark your model on real devices, especially if the app also runs camera, image preprocessing, or other CPU-heavy work.

### Using GPU Delegates

GPU Delegates offer faster, GPU-accelerated computation. There are multiple delegates available:
Expand Down
2 changes: 1 addition & 1 deletion src/loadTensorflowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const tfliteModule =
* * If you are passing in a `{ url: ... }`, make sure the URL points directly to a `.tflite` model. This can either be a web URL (`http://..`/`https://..`), or a local file (`file://..`).
*
* @param source The `.tflite` model in form of either a `require(..)` statement or a `{ url: string }`.
* @param delegates The delegates to use for computations. Uses the standard CPU delegate per default. The `core-ml` or `metal` delegates are GPU-accelerated, but don't work on every model.
* @param delegates The delegates to use for computations. Uses the standard CPU delegate per default. On Android, use `xnnpack` to opt into XNNPACK CPU acceleration. The `core-ml`, `metal`, `android-gpu`, and `nnapi` delegates are hardware-accelerated, but don't work on every model.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation is messy and all over the place - do we have proper documentation for each delegate in the delegate enum definition? Then this @param here could just say @param The delegates to use for computations. See {@linkcode Delegate}

* @returns The loaded Model.
*/
export async function loadTensorflowModel(
Expand Down
2 changes: 1 addition & 1 deletion src/useTensorflowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type TensorflowPlugin =
* * If you are passing in a `{ url: ... }`, make sure the URL points directly to a `.tflite` model. This can either be a web URL (`http://..`/`https://..`), or a local file (`file://..`).
*
* @param source The `.tflite` model in form of either a `require(..)` statement or a `{ url: string }`.
* @param delegates The delegates to use for computations. Uses the standard CPU delegate per default. The `core-ml` or `metal` delegates are GPU-accelerated, but don't work on every model.
* @param delegates The delegates to use for computations. Uses the standard CPU delegate per default. On Android, use `xnnpack` to opt into XNNPACK CPU acceleration. The `core-ml`, `metal`, `android-gpu`, and `nnapi` delegates are hardware-accelerated, but don't work on every model.
* @returns The state of the Model.
*/
export function useTensorflowModel(
Expand Down