An Introduction to TensorFlow.Js

Chidi O
Chidi O
Jul 24, 2020 · 4 min read

What is TensorFlow.js?

Tensorflow.js is a JavaScript framework developed by Google that enables developers to train and build machine learning (ML) models to be used in the browser. Developers also have the option of using pre-trained models in lieu of training their own.

But wait, what is machine learning?

Machine learning is field of artificial intelligence (AI) which provides computers the ability to learn and improve the execution of tasks without any explicit instructions. Machine learning programs can access data and use it learn for themselves.

A ML program works by creating a model — much like a mathematical model, with various inputs and outputs. Models are fed with training data and “trains” itself by tweaking parameters of the model in order to minimize the amount of error of the model over time. In short, the program will change the model to try to make its output match the desired output.

History

Before there was Tensorflow.js, there was TensorFlow. Also developed by Google, TensorFlow is an open source machine learning framework built in C++. It combines a number of machine learning and deep learning models and algorithms. Tensorflow uses Python to provide a convenient front-end API for building applications while executing applications in C++.

Before TensorFlow.js came into the scene, machine learning in javascript was primarily executed by use of an API. The server would deploy the model at the client’s request using JavaScript.

In 2017, a Google launched a project called DeepLearn.js, enabled machine learning in JavaScript without the need for an API. Later on in 2018, the DeepLearn.js team was merged with the TensorFlow team to form TensorFlow.js.

What makes TensorFlow.js so useful?

Tensorflow.js is fast as it uses WebGL (a JavaScript graphics API), so it has great performance. A Node.js version of TensorFlow, tfjs-node, exists and offers even more efficient performance over the browser version.

Tensorflow.js allows the use of pre-trained models which means that developers new to machine learning, but want to integrate it into their projects can get started right away building applications — such as an audio recognition app — without having to put in the time necessary to train their own models. It allows machine learning to be more accessible than it previously was.

TensorFlow.js also allows you to load models trained with the Python version of TensorFlow. This enables developers to build and train a model using Python and then load it into your JavaScript app. The benefit to this technique is that it can tremendously improve performance because you don’t have to train the model inside the browser.

You can even use TensorFlow.js to retrain and tinker with pre-existing machine learning models with data only available client-side in the browser such as image or video data from a webcam. The opportunities are truly endless.

How to get started with TensorFlow.js

There are a number of online tutorials that can get you started with building applications using Tensorflow.js. Some of the best tutorials come from the official Tensorflow.js website itself at tensorflow.org/js/tutorials. Here you can learn how to build an image classifier, an app that can recognize hand drawn digits, among many other tutorials. Another great resource for getting started is this tutorial series from The Coding Train where he teaches the basics and takes his audience through the process of building a couple of regression models such as linear regression and polynomial regression.

Beginner Level Projects To Try

Build an image classifier: In building this project, you will learn both learn how to train your own custom image classifier and how to use a pre trained model for classification.

Create art: You can learn to make their own unique and beautiful works of art with the application of machine learning.

Implement real-time object detection: In this tutorial you will learn how to build a web app that can detect objects through the webcam.

Play games: While Artificial Intelligence in video games isn’t a new concept, TensorFlow.js enables beginners to make their first AI video game by teaching an AI to play pong inside the browser.

What’s next?

As machine learning increases in popularity along with the use of JavaScript in development, TensorFlow.js will also continue to increase in its popularity. The library is regularly updated with features that make it more useful and easier to use for developers. In many ways, TensorFlow.js democratizes the use of machine learning, no longer requiring very capable developers and engineers to receive a math degree before being able to incorporate machine learning into important and interesting projects. With the use of pre-trained models, machine learning frameworks like TensorFlow.js become easily importable vehicles for learning and tinkering with machine learning. My prediction is that in the future technologies like TensorFlow.js will increasingly abstract away a lot of the conceptual and mathematical understanding required to perform useful tasks with machine learning.

Conclusion

Now that I’ve convinced you of how useful and beginner-friendly that TensorFlow.js can be, I recommend that you create something with it. You will be pleasantly surprised about the outcome you can achieve in a short amount of time and I assure you that you will learn a lot in the process. If you run into any roadblocks during the creation of your project, refer to the official documentation and the several tutorials that are available online. Good luck!

The Startup

Get smarter at building your thing. Join The Startup’s +724K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store