09.05.2023 Views

pdfcoffee

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

TensorFlow for Mobile and IoT and TensorFlow.js

TensorFlow.js

TensorFlow.js is a JavaScript library for machine learning models that can work

either in vanilla mode or via Node.js. In this section we are going to review both

of them.

Vanilla TensorFlow.js

TensorFlow.js is a JavaScript library for training and using Machine Learning (ML)

models in a browser. It is derived from deeplearn.js, an open source, hardwareaccelerated

library for doing Deep Learning (DL) in JavaScript, and is now a

companion library to TensorFlow.

The most common use of TensorFlow.js is to make pretrained ML/DL models

available on the browser. This can help in situations where it may not be feasible to

send client data back to the server due to network bandwidth or security concerns.

However, TensorFlow.js is a full stack ML platform, and it is possible to build and

train an ML/DL model from scratch, as well as fine-tune an existing pretrained

model with new client data.

An example of a TensorFlow.js application is the TensorFlow Projector (https://

projector.tensorflow.org), which allows a client to visualize their own data (as

word vectors) in 3-dimensional space, using one of several dimensionality reduction

algorithms provided. There are a few other examples of TensorFlow.js applications

listed on the TensorFlow.js demo page (https://www.tensorflow.org/js/demos).

Similarly to TensorFlow, TensorFlow.js also provides two main APIs – the Ops

API, which exposes low-level tensor operations such as matrix multiplication, and

the Layers API, which exposes Keras-style high-level building blocks for neural

networks.

At the time of writing, TensorFlow.js runs on three different backends. The fastest

(and also the most complex) is the WebGL backend, which provides access to

WebGL's low-level 3D graphics APIs and can take advantage of GPU hardware

acceleration. The other popular backend is the Node.js backend, which allows the

use of TensorFlow.js in server-side applications. Finally, as a fallback, there is the

CPU-based implementation in plain JavaScript that will run in any browser.

In order to gain a better understanding of how to write a TensorFlow.js

application, we will walk through an example of classifying MNIST digits using

a Convolutional Neural Network (CNN) provided by the TensorFlow.js team

(https://storage.googleapis.com/tfjs-examples/mnist/dist/index.html).

[ 478 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!