Is It a Koala? Artificial Intelligence in Javascript and TensorFlow.js

28/03/2020 Filip K

AI in your Browser

Tensorflow.js brings machine learning and its possibilities to JavaScript. It is an open source library built to create, train, and run machine learning models in the browser and Node.js

Training and building complex models can take a considerable amount of resources and time. Some models require massive amounts of data to provide acceptable accuracy. And, if computationally intensive, may require hours or days of training to complete. All that taken into consideration, you may not find the browser to be the ideal environment for building such models.

A more appealing use case is importing and running existing models. Depending on the problem you are trying to solve, there might be a model already trained with a data set and for a specific purpose which you can use and import in your code.

Proof of Concept

For example, let’s say you want to build a web app to predict if an image is a picture of a koala. A popular image classification model is called MobileNet and is available as a pre-trained model with Tensorflow.js.

Using that, you can create the app in a few minutes with just a few lines of code.
I’m not joking – this is it:

For presentational purposes I have created a simple app in ReactJS that does exactly what I have described above – predicts if an image is a picture of a koala. 

You can find the whole source code here

As you can see, it is really easy to build an app like this in your browser. TensorFlow.js does everything for you, you just work with the data you get back.

Summary

Implementing Tensorflow models in your web app is a really easy task that requires no knowledge of neural networks or AI as a whole. You can implement it with just under 20 lines of code.

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna.