jinjingforever / tflite-support

TFLite Support is a toolkit that helps users to develop ML and deploy TFLite models onto mobile / ioT devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

  1. 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).
  2. 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.
  3. The cpp code is here.
    • tflite_model_runner.* implement the model runner.
    • tflite_model_runner_wasm.cc sets up the WASM related bindings.
    • The BUILD file uses the wasm_cc_binary rule to build the WASM module. It is currently linking with XNNPACK, with WASM SIMD and multi-threading turned on.
  4. 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 the bazel 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.

About

TFLite Support is a toolkit that helps users to develop ML and deploy TFLite models onto mobile / ioT devices.

License:Apache License 2.0


Languages

Language:C++ 47.7%Language:Java 19.6%Language:Python 12.6%Language:Starlark 9.2%Language:Objective-C 4.3%Language:C 2.5%Language:Jupyter Notebook 1.4%Language:JavaScript 0.9%Language:Shell 0.8%Language:Swift 0.7%Language:Objective-C++ 0.3%Language:Makefile 0.1%Language:Batchfile 0.0%Language:HTML 0.0%