A Simple Library That Helps You Run TFLite Models in the Browser.
npm install tflite-helper
$ npm install tflite-helper
`
Preparation
To use this library you'll need to host all the files from the wasm/dist folder in the same path on your server.
ex. /tflite-helper
\> tflite-helper.js
\> tflite-helper.wasm
\> tflite-helper-simd.js
\> tflite-helper-simd.wasm
You'll also need to host your model's .tflite file.
Usage
`javascript
import createModel from 'tflite-helper';
// model_path - The URL from which to load the .tflite model file - ex. /model.tflite
// module_path - The URL from which to load the emscipten module and wasm files - ex. /tflite-helper/
const model = await createModel(model_path, module_path);
// Model Input/Ouput:
// id: number
// type: number
// offset: number
// size: number
// dimensions: number[]
// data: TypedArray - raw data of input / output (readable/writeable)
// Note: data is a getter so make sure to cache it in loops
model.inputs; // Array of model inputs
model.outputs; // Array of model outputs
const input_data = model.inputs[0].data;
// Apply changes to input data
model.invoke(); // Commonly known as predict
const output_data = model.outputs[0].data;
// Read output data
model.free(); // Free the model \w all it's memory
``