Learning TensorFlow.js

Book description

Given the demand for AI and the ubiquity of JavaScript, TensorFlow.js was inevitable. With this Google framework, seasoned AI veterans and web developers alike can help propel the future of AI-driven websites. In this guide, author Gant Laborde (Google Developer Expert in machine learning and the web) provides a hands-on end-to-end approach to TensorFlow.js fundamentals for a broad technical audience that includes data scientists, engineers, web developers, students, and researchers.

You'll begin by working through some basic examples in TensorFlow.js before diving deeper into neural network architectures, DataFrames, TensorFlow Hub, model conversion, transfer learning, and more. Once you finish this book, you'll know how to build and deploy production-readydeep learning systems with TensorFlow.js.

  • Explore tensors, the most fundamental structure of machine learning
  • Convert data into tensors and back with a real-world example
  • Combine AI with the web using TensorFlow.js
  • Use resources to convert, train, and manage machine learning data
  • Build and train your own training models from scratch

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Let’s Do This
    2. Why TensorFlow.js?
    3. Who Should Read This Book?
    4. Book Overview
      1. The Chapters
      2. The Takeaway
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  3. 1. AI Is Magic
    1. The Path of AI in JavaScript
    2. What Is Intelligence?
    3. The History of AI
    4. The Neural Network
    5. Today’s AI
    6. Why TensorFlow.js?
      1. Significant Support
      2. Online Ready
      3. Offline Ready
      4. Privacy
      5. Diversity
    7. Types of Machine Learning
      1. Quick Definition: Supervised Learning
      2. Quick Definition: Unsupervised Learning
      3. Quick Definition: Semisupervised Learning
      4. Quick Definition: Reinforcement Learning
      5. Information Overload
    8. AI Is Everywhere
    9. A Tour of What Frameworks Provide
      1. What Is a Model?
    10. In This Book
      1. Associated Code
      2. Chapter Sections
      3. Common AI/ML Terminology
    11. Chapter Review
      1. Review Questions
  4. 2. Introducing TensorFlow.js
    1. Hello, TensorFlow.js
    2. Leveraging TensorFlow.js
    3. Let’s Get TensorFlow.js Ready
    4. Getting Set Up with TensorFlow.js in the Browser
      1. Using NPM
      2. Including a Script Tag
    5. Getting Set Up with TensorFlow.js Node
    6. Verifying TensorFlow.js Is Working
      1. Download and Run These Examples
    7. Let’s Use Some Real TensorFlow.js
      1. The Toxicity Classifier
      2. Loading the Model
      3. Classifying
    8. Try It Yourself
    9. Chapter Review
      1. Chapter Challenge: Truck Alert!
      2. Review Questions
  5. 3. Introducing Tensors
    1. Why Tensors?
    2. Hello, Tensors
      1. Creating Tensors
      2. Tensors for Data Exercises
    3. Tensors on Tour
      1. Tensors Provide Speed
      2. Tensors Provide Direct Access
      3. Tensors Batch Data
    4. Tensors in Memory
      1. Deallocating Tensors
      2. Automatic Tensor Cleanup
    5. Tensors Come Home
      1. Retrieving Tensor Data
    6. Tensor Manipulation
      1. Tensors and Mathematics
      2. Recommending Tensors
    7. Chapter Review
      1. Chapter Challenge: What Makes You So Special?
      2. Review Questions
  6. 4. Image Tensors
    1. Visual Tensors
    2. Quick Image Tensors
    3. JPGs and PNGs and GIFs, Oh My!
      1. Browser: Tensor to Image
      2. Browser: Image to Tensor
      3. Node: Tensor to Image
      4. Node: Image to Tensor
    4. Common Image Modifications
      1. Mirroring Image Tensors
      2. Resizing Image Tensors
      3. Cropping Image Tensors
      4. New Image Tools
    5. Chapter Review
      1. Chapter Challenge: Sorting Chaos
      2. Review Questions
  7. 5. Introducing Models
    1. Loading Models
      1. Loading Models Via Public URL
      2. Loading Models from Other Locations
    2. Our First Consumed Model
      1. Loading, Encoding, and Asking a Model
      2. Interpreting the Results
      3. Cleaning the Board After
    3. Our First TensorFlow Hub Model
      1. Exploring TFHub
      2. Wiring Up Inception v3
    4. Our First Overlayed Model
      1. The Localization Model
      2. Labeling the Detection
    5. Chapter Review
      1. Chapter Challenge: Cute Faces
      2. Review Questions
  8. 6. Advanced Models and UI
    1. MobileNet Again
      1. SSD MobileNet
    2. Bounding Outputs
      1. Reading Model Outputs
      2. Displaying All Outputs
    3. Detection Cleanup
      1. Quality Checking
      2. IoUs and NMS
    4. Adding Text Overlays
      1. Solving Low Contrast
      2. Solving Draw Order
    5. Connecting to a Webcam
      1. Moving from Image to Video
      2. Activating a Webcam
      3. Drawing Detections
    6. Chapter Review
      1. Chapter Challenge: Top Detective
      2. Review Questions
  9. 7. Model-Making Resources
    1. Out-of-Network Model Shopping
      1. Model Zoos
      2. Converting Models
    2. Your First Customized Model
      1. Meet Teachable Machine
      2. Use Teachable Machine
      3. Gathering Data and Training
      4. Verifying the Model
    3. Machine Learning Gotchas
      1. Small Amounts of Data
      2. Poor Data
      3. Data Bias
      4. Overfitting
      5. Underfitting
    4. Datasets Shopping
      1. The Popular Datasets
    5. Chapter Review
      1. Chapter Challenge: R.I.P. You Will Be MNIST
      2. Review Questions
  10. 8. Training Models
    1. Training 101
      1. Data Prep
      2. Design a Model
      3. Identify Learning Metrics
      4. Task the Model with Training
      5. Put It All Together
    2. Nonlinear Training 101
      1. Gathering the Data
      2. Adding Activations to Neurons
      3. Watching Training
      4. Improving Training
    3. Chapter Review
      1. Chapter Challenge: The Model Architect
      2. Review Questions
  11. 9. Classification Models and Data Analysis
    1. Classification Models
    2. The Titanic
      1. Titanic Dataset
    3. Danfo.js
      1. Preparing for the Titanic
      2. Training on Titanic Data
    4. Feature Engineering
      1. Dnotebook
      2. Titanic Visuals
      3. Creating Features (aka Preprocessing)
      4. Feature Engineered Training Results
      5. Reviewing Results
    5. Chapter Review
      1. Chapter Challenge: Ship Happens
      2. Review Questions
  12. 10. Image Training
    1. Understanding Convolutions
      1. Convolutions Quick Summary
      2. Adding Convolution Layers
    2. Understanding Max Pooling
      1. Max Pooling Quick Summary
      2. Adding Max Pooling Layers
    3. Training Image Classification
      1. Handling Image Data
    4. The Sorting Hat
      1. Getting Started
      2. Converting Folders of Images
      3. The CNN Model
      4. Training and Saving
    5. Testing the Model
      1. Building a Sketchpad
      2. Reading the Sketchpad
    6. Chapter Review
      1. Chapter Challenge: Saving the Magic
      2. Review Questions
  13. 11. Transfer Learning
    1. How Does Transfer Learning Work?
      1. Transfer Learning Neural Networks
    2. Easy MobileNet Transfer Learning
      1. TensorFlow Hub Check, Mate!
    3. Utilizing Layers Models for Transfer Learning
      1. Shaving Layers on MobileNet
      2. Layers Feature Model
      3. A Unified Model
    4. No Training Needed
      1. Easy KNN: Bunnies Versus Sports Cars
    5. Chapter Review
      1. Chapter Challenge: Warp-Speed Learning
      2. Review Questions
  14. 12. Dicify: Capstone Project
    1. A Dicey Challenge
    2. The Plan
      1. The Data
      2. The Training
      3. The Website
    3. Generating Training Data
    4. Training
    5. The Site Interface
      1. Cut into Dice
      2. Reconstruct the Image
    6. Chapter Review
      1. Chapter Challenge: Easy as 01, 10, 11
      2. Review Questions
  15. Afterword
    1. Social
    2. More Books
    3. Other Options
    4. More TensorFlow.js Code
    5. Thanks
  16. A. Chapter Review Answers
    1. Chapter 1: AI Is Magic
    2. Chapter 2: Introducing TensorFlow.js
    3. Chapter 3: Introducing Tensors
    4. Chapter 4: Image Tensors
    5. Chapter 5: Introducing Models
    6. Chapter 6: Advanced Models and UI
    7. Chapter 7: Model-Making Resources
    8. Chapter 8: Training Models
    9. Chapter 9: Classification Models and Data Analysis
    10. Chapter 10: Image Training
    11. Chapter 11: Transfer Learning
    12. Chapter 12: Dicify: Capstone Project
  17. B. Chapter Challenge Answers
    1. Chapter 2: Truck Alert!
    2. Chapter 3: What Makes You So Special?
    3. Chapter 4: Sorting Chaos
    4. Chapter 5: Cute Faces
    5. Chapter 6: Top Detective
    6. Chapter 7: R.I.P. You will be MNIST
    7. Chapter 8: The Model Architect
    8. Chapter 9: Ship Happens
    9. Chapter 10: Saving the Magic
    10. Chapter 11: Warp-Speed Learning
    11. Chapter 12: Easy as 01, 10, 11
  18. C. Rights and Licenses
    1. Unsplash License
    2. Apache License 2.0
    3. Public Domain
    4. WTFPL
    5. Creative Commons Attribution-sharealike 4.0 International License (CC BY-SA 4.0)
    6. Creative Commons Attribution 4.0 International License (CC BY 4.0)
    7. Gant Laborde and O’Reilly
    8. TensorFlow and TensorFlow.js Logos
  19. Index

Product information

  • Title: Learning TensorFlow.js
  • Author(s): Gant Laborde
  • Release date: May 2021
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781492090793