Machine Learning on the web with Tensorflowjs

Source: Deep Learning on Medium

Machine Learning on the web with Tensorflowjs

Machine Learning with TensorflowJ.js

Introduction

Machine Learning/Deep Learning has emerged as the hot new technology to persuit. Machine Learning and Deep Learning is providing solutions to vast range of complex problems which are not possible with common software design paradigms.Ranging from Finance,Healthcare to even agriculture,ML has found its place in every corner.Image Detection,Self driving cars,Chatbots,Predicting stocks,Recommendation Systems etc. and a whole lot of application have only been possible because of ML/DL.

The foundation of every Machine Learning or Deep Learning application has been Data.With enormous amount of data been generated with every activity in this world,the problem to utilize this data became a prime concern.This is where Data Science and ML came to rescue.

What is machine learning on the web?

Machine Learning with Python included a client server architecture where the business logic for the cognitive part including training and building the ML model was hosted on a web server which provided an Api endpoint to call the model from the client side using the endpoint.All the code for the cognitive part of the login were written in python.From the client side in the browser we needed to make an api call each time we made a prediction.This required the server to been always available to serve the endpoint.So if for some reason the server goes offline or there is no internet connection the client side application fails to perform or predict.For applications which required decent amount of learning or which required big sized models to work with,this was perfectly fine as such big models cannot be loaded in the browser but for applications which required small models to work with this seemed to be a costly affair.This is where Machine Learning on the web came to rescue.

The web browser has the capability to load models upto 30MB on the fly.Today we have lots of libraries which make maching learning in the browser possible.Models like MobileNet are optimized for usage on platforms with low storage and computing capacity without compromising with the accuracy of the prediction.All the cognitive code for the application are written in Javascript and can well be loading in a browser.

What is Tensorflowjs?

TensorFlow.js is a library for developing and training ML models in JavaScript, and deploying in browser or on Node.js.

With Tensorflowjs one can use off-the-shelf JavaScript models or convert Python TensorFlow models to run in the browser or under Node.js, Retrain pre-existing ML models using your own data, Build and train models directly in JavaScript using flexible and intuitive APIs. Tensorflowjs has two APIs ,the Core API and the Layers API.The Core API handles basic tensor operations where one can build basic code for the base logic.The Layers API provides a good abstraction of internal details by providing implementaion of layers to work with just like keras in Python.

Brief History of Tensorflowjs

Before going to Tensorflowjs, lets start with Tensorflow. Tensorflow was developed by Google in 2011 as their own software for Machine Learning/Deep Learning application.Tensorflow is written in C++ so the code can be executed at a very low level.It has support for languages like Python,R and Java.
So, what about Javascript.

In 2017, a project called Deeplearn.js was started which enabled ML/DL model to run without API calls.In 2018, it was renamed Tensorflow.js .
Well, if you have some background on tensorflow ,you know that Tensorflow requires GPU to execute on your machine, but the real problem comes since Javascript cannot execute on a GPU.So how do the developers tackle this problem.Well,a new API called WebGL was introduced since HTML5 supportsWebGL right out of the box,where previous HTML version failed to do so. WebGL is a JavaScript API for rendering interactive 2D and 3D graphics within any compatible web browser without the use of plug-ins.It is an interface to OpenGL,the standard library for rendering 2D and 3D graphics. WebGL enabled the execution of Javascript in the browser.

Links:
Originally from : https://mithilesh.tech/