This repo is a fork of the
tflite-support repo, with the
addition of the tflite_model_runner
related code to show how it is built
using bazel and emsdk.
- Add emscripten toolchain to the
WORKSPACE
file. This will set up emsdk and provide a useful build rule
wasm_cc_binary
that can be used to build WASM module from a cc_binary (see below). - I also added a small patch for the com_google_glog library. Without it, the emscripten build will fail on Mac/Linux. The glog v0.5.0 release has a fix for this issue, but it requires some TFLite code refactoring. I will talk to the TFLite team about this. For now we will just use the patch.
- The cpp code is here.
- The demo code is
here. To run the demo:
- Run
yarn && yarn build
in the demo directory.yarn build
runs build.sh where you can see how thebazel build
command is used and how to extract the output files. - Run
yarn start
to start the demo locally. It creates a model runner instance with the MobilenetV2 model and classfies an image. See the script.js file for details about how things are used from the JS side. - Since this build configuration is for SIMD+multi-threading, please make
sure Chrome has these two features
turned on
from
chrome://flags
. - Run
yarn run electron
to start the demo in electron.js. - Run
yarn run electron-packager
to build an electron.js app of this demo.
- Run
- The WebNN delegate support
tensorflow_lite_webnn_delegate.patch
: the WebNN delegate implementation.emscripten_webnn_support.patch
: WebNN support of emscripten.emsdk.patch
: workaround the frozen cache setting of emscripten so WebNN support can be regenerated. As the cache is cleared, the firstyarn build
would fail. Please rerun, it would succeed.- Add
TFLiteWebModelRunnerOptions.enableWebNNDelegate
to enable or disable WebNN delegate. - Demo in browser is using webnn-polyfill.
- Demo in electron.js could use WebNN-native node.js binding for more details.