I was writing a blog post about the different activation functions and how they can impact your training. I wanted to make an interactive post so was looking at running a simple model on the browser. That’s when I found Tensorflow JS.
Kudos to the people behind this. This was a great way to bring the awesomeness of Tensorflow to the browser. When using the library you can either:
- Load a pre-trained model
- Train on the browser
Let’s try and do both. We’ll work with the make_moons dataset from sklearn.
Parameters we’ll be using:
- Activation Function: tanh
- Learning Rate: 1
The data we’ll be training on:
Load a pre-trained model Link to heading
Training on python Link to heading
|
|
0:00:02.631679
That took 2.63s
Save the model to a form which can be used by TensorflowJS
|
|
Load the model in TensorflowJS via Javascript
|
|
Finally Lets see how our model predicts
Train on the browser Link to heading
Code used to train the model:
|
|
Why do we use an async function? That’s because model.fit() returns a Javascript promise. Hence we start an async function, and wait on it to finish.
Time taken to finish training: Loading
If you wait long enough, you’ll see the model finish training and prediction similar to our earlier method. The only difference is that this time it took a lot more time. On my PC it takes around 22s which is almost 1000% of the previous method.
Conclusion Link to heading
Its amazing that we can even do something on the lines of training models on browsers. But at the same time, we can see how years of optimization on the Python front of Tensorflow clearly gives it an edge over its JS counterpart.