Installing and using TensorFlow.js
As we mentioned earlier, TensorFlow.js can be installed and run in both the browser and Node.js environment. In the following paragraphs, we'll show you how to achieve this, starting off with the browser.
Setting up TensorFlow.js in the browser
There are two ways of installing TensorFlow.js in the browser. These are outlined here:
- Via script tags
- Using package managers such as Node Package Manager (npm) or Yarn
Installing via script tags
Installing TensorFlow.js via a script
tag is easy. Just place the script
tag in the header file of your HyperText Markup Language (HTML) file, as shown in the following code snippet:
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.6.0/dist/tf.min.js"></script>
To confirm that TensorFlow.js is installed, open the HTML file in the browser, and check the network tabs. You should see the name tf.min.js
and a status code of 200
, as shown in the following...