There are three main usecases of using tensorflow.js
Run the existing models
Keras models are usually created via the Python API and can be saved configuration + weights, weights only, configuration only. This format can be converted to TensorFlow.js Layers format, which can be loaded directly into TensorFlow.js for inference or for further training. Learn more about converting keras model to tensorflow.js.
If you have a SavedModel of tensorflow (SavedModel contains a complete TensorFlow program, including weights and computation and it does not require the original model building code to run, which makes it useful for sharing or deploying), then you can convert it into tensorflow.js using
Retrain existing models
If you have a pretrained model, and you want to retrain it with new data, then you can do so in tensorflow.js. This is particularly useful when you have an edge device, which you want to customize with new personalized data.
For example, you have a model which is trained by thousands of sample of voices of humans. But you want that the final model be personalized to recognize the voice of the user at the user’s device. So in this scenario, you can use the pretrained model of the voice recognition, remove the final layer and train a new (often fairly shallow) model containig the voice of user on top of the output of the truncated model.
We saw how we can use tensorflow.js to run the existing models and retrain them. But we can also use tensorflow.js to completely train the model from scratch and use it. In order to train the model from scratch, you need to be familiar with tensorflow concepts of Tensors, Layers, Optimizers and Loss Functions.
There are few helper libraries available which can be used with tensorflow.js.
- It provides a set of visualizations like bar chart, line chart etc. useful for visualizing model behaviour
- A set of high level functions for visualizing objects specific to TensorFlow.js
- A way to organize visualizations (the visor) of model behaviour that won’t interfere with the web application
tfjs-examples contains the code and usecases developed using tensorflow.js. There are many examples available. You can find examples of Binary classification – classifying website urls as normal or phishy, reinforcement learning – using deep Q learning to solve the snake game, date conversion using LSTM attention model
Online browser Demos
One of the advantage of tensorflow.js is that it can run in browser environments. So we can easily show demos in browser, which can use text, webcam, microphone, or other things for input. Tensorflow.js contains many such interesting usecases which you can check in browser itself.