concept browser in category deep learning

appears as: browser, browsers, browser
Deep Learning with JavaScript: Neural networks in TensorFlow.js

This is an excerpt from Manning's book Deep Learning with JavaScript: Neural networks in TensorFlow.js.

Due to this broad reach, the web browser is a logical choice for deploying deep-learning models, as long as the kinds of data the models expect are available in the browser. But what kinds of data are available in the browser? The answer is, many! Take, for example, the most popular applications of deep learning: classifying and detecting objects in images and videos, transcribing speech, translating languages, and analyzing text content. Web browsers are equipped with arguably the most comprehensive technologies and APIs for presenting (and, with user permission, for capturing) textual, image, audio, and video data. As a result, powerful machine-learning models can be directly used in the browser, for example, with TensorFlow.js and straightforward conversion processes. In the later chapters of this book, we will cover many concrete examples of deploying deep-learning models in the browser. For example, once you have captured images from a webcam, you can use TensorFlow.js to run MobileNet to label objects, run YOLO2 to put bounding boxes around detected objects, run Lipnet to do lipreading, or run a CNN-LSTM network to apply captions to images.

Once you have captured audio from the microphone using the browser’s WebAudio API, TensorFlow.js can run models to perform real-time spoken-word recognition. There are exciting applications with textual data as well, such as assigning sentiment scores to user text like movie reviews (chapter 9). Beyond these data modalities, the modern web browser can access a range of sensors on mobile devices. For example, HTML5 provides API access to geolocation (latitude and longitude), motion (device orientation and acceleration), and ambient light (see http://mobilehtml5.org). Combined with deep learning and other data modalities, data from such sensors opens doors to many exciting new applications.

  • With its restricted resources, the browser is only suitable for training small models. To train larger models, it is recommended you use tfjs-node, the Node.js version of TensorFlow.js; tfjs-node can use the same CPU- and GPU-parallelized kernels used by the Python version of TensorFlow.
  • 4.3.2. Saving the model from Node.js and loading it in the browser

    Training your model consumes CPU and GPU resources and takes some time. You don’t want to throw away the fruit of training. Without saving the model, you would have to start from scratch the next time you run main.js. This section shows how to save the model after training and export the saved model as files on the disk (called a checkpoint or an artifact). We will also show you how to import the checkpoint in the browser, reconstitute it as a model, and use it for inference. The final part of the main() function in main.js consists of the model-saving code in the following listing.

    Listing 4.7. Saving the trained model to the file system in tfjs-node
      if (modelSavePath != null) {
        await model.save(`file://${modelSavePath}`);
        console.log(`Saved model to path: ${modelSavePath}`);
      }

    The save() method of the model object is used to save the model to a directory on your file system. The method takes a single argument, which is a URL string that begins with the scheme file://. Note that it is possible to save the model on the file system because we are using tfjs-node. The browser version of TensorFlow.js also provides the model.save() API but cannot access the machine’s native file system directly because the browser forbids that for security reasons. Non-file-system saving destinations (such as the browser’s local storage and IndexedDB) will have to be used if we are using TensorFlow.js in the browser. Those correspond to URL schemes other than file://.

    Figure 12.8. The architecture of an Electron.js-based desktop application that utilizes TensorFlow.js for accelerated deep learning. Different compute backends of TensorFlow.js can be invoked, from either the main backend process or the in-browser renderer process. Different compute backends cause models to be run on different underlying hardware. Regardless of the choice of compute backend, the code that loads, defines, and runs deep-learning models in TensorFlow.js is largely the same. The arrowheads in this diagram indicate invocation of library functions and other callable routines.