npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tflite-helper

v0.9.4

Published

A Simple Library That Helps You Run TFLite Models in the Browser.

Downloads

55

Readme

TFLite-Helper v0.9.4

A Simple Library That Helps You Run TFLite Models in the Browser.

Base code taken from https://github.com/Volcomix/virtual-background

Installation

$ 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

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

Adding Custom Operations

You'll need at least some very basic Bazel experience to do this.
Sometimes TFLite models use Custom Operations. You'll need to find where that Custom Operation comes from, add it to the Docker Container using the Dockerfile or the WORKSPACE file, add it as a dependency to both binaries in the BUILD file and finally import it and register it in the loadModel function in the main.cpp file. You can see how to register it from the way this library registers the Convolution2DTransposeBias from MediaPipe.
You'll will also need to build the WASM files from scratch (see below).

Building The WASM Files From Scratch

If you don't want to use the files from wasm/dist, then you'll have to build them yourself.
You'll need to install Docker if you haven't done that already.
Change the docker-username in the build.sh or build.bat file in the wasm folder and run the script.

TODO

  • Switch from ES6 to ES5 with Emscripten, and load the module files with fetch to support more browsers.