Through a series of articles, I will try to introduce you (primarily JavaScript developers) to the world of machine learning (ML). In the first part, I will talk in general about machine learning, the TensorFlow.js library, and the benefits of using it.
Machine learning is an area of artificial intelligence that can freely be defined as the study of programs and algorithms that allow computers to perform tasks without special instructions.
TensorFlow.js is an open-source library (developed by Google) for creating and executing machine-learned algorithms in JavaScript. TensorFlow models can be executed in web browsers or in the Node.js environment. This library provides a set of APIs that are compatible with those from Python, providing the ability to use the JavaScript model in the Python ecosystem and vice versa.
The model running in the browser means that from the user's perspective, there is no need to install additional libraries or drivers. Just open the website and the program is ready to run.
Because JavaScript can run on a variety of environments, once written machine learning code can be easily executed on the following platforms:
Privacy
We can train the model in the user's web browser without sending data to the web server. This can sometimes be a condition for compliance with local laws, such as GDPR.
Speed
Since we do not have to send data to the server, inference (the act of classifying data) can be faster. In addition, we have direct access to device sensors such as camera, microphone, GPS, accelerometer and more if the user grants us access.
Reach
Anyone can open the web page in their browser with one click and use what we have created.
Price
No server means that the only thing we must pay for is a CDN to host our HTML, CSS, JS files. The cost of a CDN is much lower than renting and maintaining a server.
Model Size
We may sometimes work with very large models. Such models cannot run in a web browser due to memory limitations per browser tab. To be able to run such models we can use our own server with Node.js installed.
IoT
Node.js is supported on IoT devices such as the Raspberry Pi, which in turn means we can run TensorFlow.js models on such devices, as well.
You can learn more about the TensorFlow.js library by following the links below.
Learn TensorFlow.js - Deep Learning and Neural Networks with JavaScript
In the following article I’ll tell you more about the architecture of this library, and a practical example (using an IoT device to identify a free parking space) will allow you to get to know it better.