A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learning.oreilly.com/library/view/learning-tensorflowjs/9781492090786/app02.html below:

B. Chapter Challenge Answers - Learning TensorFlow.js [Book]

May 2021

Intermediate to advanced content level Intermediate to advanced

338 pages

7h 44m

English

Associated roles Content preview from Learning TensorFlow.js Appendix B. Chapter Challenge Answers Chapter 2: Truck Alert!

The MobileNet model can detect all kinds of different trucks. You could solve this problem by going through the list of identifiable trucks, or you can simply search for the word truck in the given list of class names. For simplicity, the provided answer did the latter.

The entire solution with HTML and JavaScript is here:

<!DOCTYPE html>
<html>
  <head>
    <script
    src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.7.0/dist/tf.min.js">
  </script>
    <script
    src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet@1.0.0">
  </script> 
    <script>
      mobilenet.load().then(model => {
        const img = document.getElementById('myImage'); 
        // Classify the image
        model.classify(img).then(predictions => {
          console.log('Predictions: ', predictions);
          // Was there a truck?
          let foundATruck
          predictions.forEach(p => {
            foundATruck = foundATruck || p.className.includes("truck") 
          })
          // TRUCK ALERT!
          if (foundATruck) alert("TRUCK DETECTED!") 
        });
      });
    </script>
  </head>
  <body>
    <h1>Is this a truck?</h1>
    <img id="myImage" src="truck.jpg" width="100%"></img> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.Start your free trial

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4