Open In App
Related Articles

Tensorflow.js Introduction

Like Article
Save Article
Report issue

What is Tensorflow.js?

TensorFlow.js is a JavaScript library for training and deploying machine learning models on web applications and in Node.js. You can develop the machine learning models from scratch using tensorflow.js or can use the APIs provided to train your existing models in the browser or on your Node.js server.

To learn more you can directly go to this link:

Prerequisite: Before starting Tensorflow.js, you need to know the following:

For browser:

  • HTML: Basics knowledge of HTML is required
  • JavaScript: Good knowledge of JS is required

For server-side:

  • Node.js: Having a good command of Node.js. Also since Node.js is a JS runtime, so having command over JavaScript would help a lot.

Other requirements:

  • NPM or Yarn: These are packages that need to be installed in your system.

Setting Up Tensorflow.js:

Browser Setup There are two ways to add TensorFlow.js in your browser-based application:

  • Using script tags.
  • Installation from NPM

1. Using Script tags: Add the following script tag to your main HTML file.

<script src=””></script>



<!DOCTYPE html>
<html lang="en">
    <script src=
        // Value of a scalar
        let value = "Hello Geeks! Tensorflow here."
        // Creating the value of a scalar
        let tens = tf.scalar(value)



2. Using NPM/ yarn: We can either use NPM or Yarn to install tensorflow.js.

yarn add @tensorflow/tfjs


npm install @tensorflow/tfjs

Node.js Setup:

Option 1: Install TensorFlow.js with native C++ bindings.

yarn add @tensorflow/tfjs-node


npm install @tensorflow/tfjs-node

Option 2: (Linux Only) If your system has a NVIDIA® GPU with CUDA support, use the GPU package even for higher performance.

yarn add @tensorflow/tfjs-node-gpu


npm install @tensorflow/tfjs-node-gpu

Option 3: Install the pure JavaScript version. This is the slowest option performance-wise.

yarn add @tensorflow/tfjs


npm install @tensorflow/tfjs

Last Updated : 24 May, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads