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.

The steps here are similar to a normal supervised model development pipeline –

load the data, define, train, and evaluate the model.

Chapter 13

JavaScript works inside a browser environment, within an HTML page. The

HTML file (named index.html) below represents this HTML page. Notice the two

imports for TensorFlow.js (tf.min.js) and the TensorFlow.js visualization library

(tfjs-vis.umd.min.js) – these provide library functions that we will use in our

application. JavaScript code for our application comes from data.js and script.js

files, located in the same directory as our index.html file:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Import TensorFlow.js -->

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.0.0/

dist/tf.min.js"></script>

<!-- Import tfjs-vis -->

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjsvis@1.0.2/dist/tfjs-vis.umd.min.js"></script>

<!-- Import the data file -->

<script src="data.js" type="module"></script>

<!-- Import the main script file -->

<script src="script.js" type="module"></script>

</head>

<body>

</body>

</html>

For deployment, we will deploy these three files (index.html, data.js, and

script.js) on a web server, but for development we can start a web server up by

calling a simple one bundled with the Python distribution. This will start up a web

server on port 8000 on localhost, and the index.html file can be rendered on the

browser at http://localhost:8000:

python -m http.server

[ 479 ]

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

Saved successfully!

Ooh no, something went wrong!