#native_company# #native_desc#
#native_cta#

What is TensorFlow?

Let's get physical

Sometimes, nothing beats holding a copy of a book in your hands. Writing in the margins, highlighting sentences, folding corners. So this book is also available from Amazon as a paperback.

Buy now on Amazon

TensorFlow (https://www.tensorflow.org/) itself is an incredibly powerful machine learning and deep learning library. It allows you to build these constructs called Data Flow Graphs, which represent a Machine Learning model. It was developed by Google Brain for internal use, and open-sourced in November 2015.

It allows you to define mathematical functions and scale the execution of those functions in parallel across multiple cores on your CPU, multiple cores on a GPU, as well as across multiple computers.

Note

=== Your GPU, Graphics Processing Unit, is a card inside your computer designed to figure out how to draw things on a screen. It’s like a CPU but a lot less general-purpose, it can do one thing but do that thing well and now really fast. It does that by running 100s of calculations in parallel; it just happens that these types of calculations are also perfect for machine learning.

You may hear the term GPU being used a lot with Machine Learning; your graphics card is more useful to you in machine learning than your main CPU. ===

What is TensorFlow.js?

Here is where it gets exciting, TensorFlow is built using C++, it’s incredibly fast, but that doesn’t help you so much if you are a JavaScript developer.

In 2018 Google announced TensorFlow.js (https://www.tensorflow.org/js/). I have to admit that at first, I assumed that TensorFlow.js was just a Node.js binding to TensorFlow. I thought you could only use TensorFlow.js if TensorFlow was installed on your computer and you could only use it from Node.js, not from the browser. I was wrong on both counts.

Important

TensorFlow.js is TensorFlow re-written from the ground up in JavaScript.

That deserves repeating, “TensorFlow.js is TensorFlow re-written from the ground up in JavaScript”.

What this means is that to use TensorFlow.js you don’t need to install any dependencies.

You only need to import one package, like so:

import * as ts from '@tensroflow/tfjs';

Or, even simpler, you can just add one script tag in your HTML file, like so:

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"></script>

That’s it, that’s all you need to get started doing Machine Learning in the browser.

Core API vs. Layers API

The original TensorFlow Python API can be used for a wide variety of purposes, anything requiring large amounts of parallel mathematical calculations but is pretty low level.

The community responded by building higher-level packages like keras[1], which take care of a lot of the boilerplate in TensorFlow writing Neural Networks.

The TensorFlow.js library consists of two different packages, the first is a flexible low-level core API, which is syntactically very similar to the TensorFlow Python API.

The core API is low level, so if all you are building is a Neural Network, then you can end up writing lots of boilerplate code for each project.

For TensorFlow.js the team decided to incorporate a Keras style API as part of the package, and it’s called the layers API.

Note

In this course, we will be covering the core API so we can build a good understanding of the internals, and then we will move onto using the layers API.

Node.js TensorFlow vs Browser TensorFlow.js

The version of TensorFlow.js I discuss above I will refer to as browser TensorFlow.js; however, that is inaccurate, it can be used in the browser OR within Node.js.

There is a crucial difference between the browser version of TensorFlow.js and the version you can use with Node.js.

When used in the browser, it will use the GPU to perform calculations through the browsers Web GL API. This can result in a 100x performance improvement vs. running on the vanilla CPU of your computer.

When used via Node.js, it will only use the vanilla CPU,

To perform slightly faster via Node.js you can use this package:

import * as tf from '@tensorflow/tfjs-node'

This installs the TensorFlow binary into your node_modules folder. You are controlling a standard TensorFlow instance via JavaScript bindings.

If you are running on Linux, you can use the GPU accelerated version of TensorFlow.js via:

import * as tf from '@tensorflow/tfjs-node-gpu'

This will run calculations on the GPU with CUDA[2], resulting again in significant speed improvement.

You can find more information about how to run TensorFlow.js from within Node.js from this link https://www.tensorflow.org/js/guide/nodejs.



Advanced JavaScript

This unique course teaches you advanced JavaScript knowledge through a series of interview questions. Bring your JavaScript to the 2021's today.

Level up your JavaScript now!