Make tflite model run directly with tfjs
To get help from the community, check out our Google group. This is not a bug rather a feature request. As TensorFlow library provides TFLite models to run on Android, iOS platform, can we a build a tfjs wrapper to allow tfjs to directly load TFlite model in browser. This will allow same model being used across multiple platforms.
TensorFlow.js version
Browser version
Describe the problem or feature request
Code to reproduce the bug / link to feature request
I don't think this is something we'll ever support -- you can convert a savedmodel to tfjs without tf lite.
closing this as there is no support for feature request.
Question @mbostock and @rthadur, this is my first time working with javascript, so, let me know if I am way off, js is a client-side programming language right and tf.lite works on edge, so, why not have a way to load tf.lite directly via tfjs, seems pretty straightforward.
Unfortunately it’s not as simple as you’d think. Is there a use case you have a in mind that we can’t solve with TensorFlow.js itself?
oh no, @nsthorat it's more of a architecture & performance decision, we have a voice assistant in tensorflow and to move it to edge there are two ways, convert it to tf.lite and write in java for android or convert it into tf.js and write in js, I read tf.lite has much better performance for ML but writing in js would be convenient, not to mention, having to learn Java to do this, so was wondering if I could convert from tf to tf.lite and then load the model via js. If you have any ideas, it would be really helpful
Got it.
In the browser, compiling TF Lite will be too large of a binary to run directly and will be much slower than our kernels.
In Node.js, we're working on natively executing SavedModels, and we are also working on headless WebGL bindings.
These two should cover everything you'd need, unless I'm missing something!
Hey @nsthorat thanks a lot man, was going through tf node.js and it looks like that would work great. Appreciate your help 🙂
No problem :)
@nsthorat Have a use case that doesn't require a wrapper. Let me know if this is possible.
Question: Is it possible to convert a .tflite file to a .pb file then use tfjs-converter to convert to a js model?
Context: I'm using Firebase's AutoML library -- it's pretty sweet, it creates generic .tflite files (TensorFlow lite models) for me I can plug into my native mobile app (I don't have access to a .pb output).
Reading tfjs-converter, maybe I can convert a tf saved model into a js model format offline. However, doesn't seem you can convert .tflite to json.
Hi @opiepj, we're actively working on getting TensorFlow.js models directly supported in AutoML, stay tuned!
https://github.com/intel/webml-polyfill this is a way of running tflite on web
@startupgurukul unfortunately that requires a custom chromium build.
Hi Nikhil, My understanding is that polyfill is enough to run in any browser and custom chromium build if one needs native performance.
Here are some examples they provide https://intel.github.io/webml-polyfill/examples/
@rthadur I've checked the examples, it looks like i've to write lot of javascript code like this to work with smart reply https://github.com/intel/webml-polyfill/blob/master/examples/face_recognition/utils.js?
@nsthorat what should we do if we want the benefits of a fast tflite model but we want to run it on the web?
It doesn't seem possible to convert a .tflite model back into a Tensorflow model so that we can convert it into a TFjs model.
@NathanBWaters where did you get the .tflite model? .tflite models come from SavedModels which can be converted to tfjs.
@nsthorat thanks for responding so quickly. We are seeing faster results using a tflite blazeface model (see here) than using the TF model converted into TFjs.
So, though we can convert the original SavedModels into tfjs, we want to use the faster more optimized .tflite version of the model.
@NathanBWaters We actually already have blazeface converted in tfjs: https://github.com/tensorflow/tfjs-models/tree/master/blazeface
Hope this helps!
@NathanBWaters We actually already have blazeface converted in tfjs: https://github.com/tensorflow/tfjs-models/tree/master/blazeface
@nsthorat Will it be possible for you to share how you did the conversion?
@rrjanbiah We converted it from the internal SavedModel (not sure why the team didn’t want to release it).