Serengeti logo BLACK white bg w slogan
Menu

TensorFlow.js – Machine Learning for JavaScript Developers – Part I

Damir Kustura, Frontend Developer
01.02.2022.

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.

What is Machine Learning?

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.

What is TensorFlow.js?

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.

Where can it be used?

Because JavaScript can run on a variety of environments, once written machine learning code can be easily executed on the following platforms:

  • In a web browser on the client side using vanilla JavaScript or a popular JavaScript framework such as ReactJS
  • On the server side or even in IoT devices such as the Raspberry Pi using Node.js
  • In desktop applications using Electron
  • In native mobile applications using React Native.

Benefits of Client-Side Execution

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.

Benefits of Server-Side Execution

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.

Want to Learn More?

You can learn more about the TensorFlow.js library by following the links below.

TensorFlow.js

TensorFlow.js - Tutorials

GitHub - TensorFlow Examples

Learn TensorFlow.js - Deep Learning and Neural Networks with JavaScript

What’s Next?

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.

Let's do business

The project was co-financed by the European Union from the European Regional Development Fund. The content of the site is the sole responsibility of Serengeti ltd.
cross