paint-brush
Start Using TensorFlow.js — Without Leaving This Articleby@bourdakos1
16,154 reads
16,154 reads

Start Using TensorFlow.js — Without Leaving This Article

by Nick BourdakosDecember 6th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

One of the largest obstacles for beginners getting experience with artificial intelligence and machine learning can honestly be the setup.

Company Mentioned

Mention Thumbnail
featured image - Start Using TensorFlow.js — Without Leaving This Article
Nick Bourdakos HackerNoon profile picture

One of the largest obstacles for beginners getting experience with artificial intelligence and machine learning can honestly be the setup.

I’m not going to lie, there are still plenty of days that completely slip away, just trying to get Python, TensorFlow and my GPU to cooperate. Does this make me question my abilities as a competent software engineer? Yes, yes it does.

I digress.

So what is TensorFlow.js and how can it help us? From the official page, TensorFlow.js is, “A JavaScript library for training and deploying ML models in the browser and on Node.js.”

What does that mean for us? We can try it out right from this Medium article!

The Demo

In this demo we are using a deep learning model called “MobileNet”. MobileNet is a type of Convolution Neural Network, a model architecture that is good at image classification.

Note: To learn more about what artificial intelligence actually sees, check out my other article.

The Code

Using TensorFlow.js to classify an image with MobileNet is as easy as 3 lines of code:



mobilenet.load().then(model => model.classify(myImage)).then(predictions => // Use predictions)

Final Thoughts

At the time of writing this post TensorFlow provides 5 official models, that are just as easy to use:

  • [mobilenet](https://github.com/tensorflow/tfjs-models/tree/master/mobilenet): Classify images with labels from the ImageNet database.
  • [posenet](https://github.com/tensorflow/tfjs-models/tree/master/posenet): Realtime pose detection. Blog post here.
  • [coco-ssd](https://github.com/tensorflow/tfjs-models/tree/master/coco-ssd): Object detection based on the TensorFlow object detection API.
  • s[peech-commands](https://github.com/tensorflow/tfjs-models/tree/master/speech-commands): Classify 1 second audio snippets from the speech commands dataset.
  • [knn-classifier](https://github.com/tensorflow/tfjs-models/tree/master/knn-classifier): Create a custom k-nearest neighbors classifier. Can be used for transfer learning.

However, if none of these models suffice, you can also create/train your own, but that’s for another article.

For fun, I challenge you to look at the PoseNet documentation and try to match the results of the cover photo. But, if you get stuck here’s the code and demo:

Thanks for reading! If you have any questions, feel free to reach out at [email protected], connect with me on LinkedIn, or follow me on Medium and Twitter.

If you found this article helpful, it would mean a lot if you gave it some applause👏 and shared to help others find it! And feel free to leave a comment below.