Leanpub Header

Skip to main content

Machine Learning with TensorFlow.js

From Fundamentals to Production in JavaScript and TypeScript

Machine Learning with TensorFlow.js
This book is 100% completeLast updated on 2026-09-01

Build real machine learning applications with TensorFlow.js, from your first model to production-ready systems. Learn how to train and deploy models in the browser and Node.js, tackle real-world challenges and explore modern techniques with practical JavaScript and TypeScript examples you can run and adapt.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
207
Pages
About

About

About the Book

TensorFlow.js has evolved into a complete, production-ready machine learning platform for the JavaScript ecosystem. This book takes you from foundational concepts through advanced techniques, showing you how to build, train and deploy machine learning models directly in the browser and Node.js. Whether you are adding real-time object detection to a web application, running server-side inference at scale, or experimenting with cutting-edge architectures like attention mechanisms, this book provides the practical knowledge and architectural guidance you need. Every chapter includes complete, runnable code examples using modern TensorFlow.js APIs and current JavaScript practices, with clear explanations of not just how things work but why they work and when to use each approach.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

From Fundamentals to Production in JavaScript and TypeScript

Introduction: Why Machine Learning in JavaScript?

  1. What This Book Covers
  2. Who Should Read This Book
  3. How to Use the Code Examples
  4. A Note on Versions and Changes

Chapter 1: Machine Learning Meets JavaScript

  1. Why Machine Learning in JavaScript?
  2. How TensorFlow.js Fits Into the ML Landscape
  3. Your First Prediction in 30 Seconds
  4. Browser vs Node.js: Two Environments, One API
  5. Setting Up Your Development Environment
  6. Summary

Chapter 2: Tensors, the Building Blocks

  1. What Is a Tensor?
  2. Creating Tensors in TensorFlow.js
  3. Tensor Shapes, Ranks, and Dimensions
  4. Element-wise Operations and Broadcasting
  5. Reshaping, Slicing, and Indexing
  6. The Mathematics Behind the Operations
  7. Summary

Chapter 3: Memory Management and Performance Basics

  1. How TensorFlow.js Manages Memory
  2. Tensors, GPU Buffers, and Garbage Collection
  3. Disposing Tensors and Avoiding Leaks
  4. tf.tidy and Automatic Cleanup
  5. Monitoring Memory Usage
  6. Performance Profiling Basics
  7. Summary

Chapter 4: The Sequential API and Core Layers

  1. Understanding Neural Networks Intuitively
  2. Building Your First Model with Sequential
  3. Dense Layers and Linear Transformations
  4. Activation Functions and Non-linearity
  5. Convolutional Layers for Spatial Data
  6. Pooling and Dimensionality Reduction
  7. Summary

Chapter 5: Training Models from Scratch

  1. The Training Process Step by Step
  2. Loss Functions: Measuring Model Quality
  3. Optimizers and Learning Rate Strategies
  4. Compiling a Model
  5. The fit() Method and Training Loop
  6. Callbacks for Monitoring and Control
  7. Summary

Chapter 6: Evaluation, Prediction, and Debugging

  1. Evaluating Model Performance
  2. Making Predictions with model.predict()
  3. Understanding Confusion Matrices and Metrics
  4. Debugging Training Problems
  5. Overfitting, Underfitting, and Regularization
  6. Learning Curves and Diagnostics
  7. Summary

Chapter 7: Advanced Model Architectures

  1. The Functional API for Complex Graphs
  2. Recurrent Layers and Sequence Modeling
  3. LSTM and GRU Networks
  4. Attention Mechanisms in TensorFlow.js
  5. Custom Layers and Operations
  6. Hyperparameter Tuning Strategies
  7. Summary

Chapter 8: Data Handling and Preprocessing

  1. The Data Pipeline in TensorFlow.js
  2. Loading Data from Various Sources
  3. Normalization and Standardization
  4. One-hot Encoding and Label Transformation
  5. Image Preprocessing and Augmentation
  6. Text Tokenization and Embedding
  7. Summary

Chapter 9: Computer Vision with TensorFlow.js

  1. Image Classification Fundamentals
  2. Using Pretrained Models: MobileNet and ResNet
  3. Transfer Learning for Custom Classifiers
  4. Object Detection with COCO-SSD
  5. Body Pose Estimation and Face Detection
  6. Building a Custom Vision Application
  7. Summary

Chapter 10: Natural Language Processing in the Browser

  1. Representing Text as Numbers
  2. Sentiment Analysis with Pretrained Models
  3. Building a Text Classifier from Scratch
  4. Sequence-to-Sequence Models
  5. Word Embeddings in TensorFlow.js
  6. Practical NLP Applications
  7. Summary

Chapter 11: Time-Series Forecasting and Sequential Data

  1. Understanding Time-Series Data
  2. Preparing Sequences for Modeling
  3. Simple Baseline Models
  4. LSTM-Based Forecasting
  5. Evaluating Time-Series Predictions
  6. Real-World Forecasting Example
  7. Summary

Chapter 12: Saving, Loading, and Model Formats

  1. The TensorFlow.js Model Format
  2. Saving Models in the Browser
  3. Saving Models in Node.js
  4. Converting Python Keras Models to TensorFlow.js
  5. Loading Models from Different Sources
  6. Quantization and Model Compression
  7. Summary

Chapter 13: Backend Systems and GPU Acceleration

  1. How Backends Work in TensorFlow.js
  2. The WebGL Backend and GPU Compute
  3. WebGPU Backend and the Future
  4. CPU Backend Fallbacks
  5. TensorFlow C++ Backend for Node.js
  6. Choosing and Configuring Backends
  7. Summary

Chapter 14: Server-Side Machine Learning with Node.js

  1. Running TensorFlow.js in Node.js
  2. Building an Inference API
  3. Batch Processing and Efficiency
  4. Scaling Inference Services
  5. Integration with Web Frameworks
  6. Production Monitoring and Observability
  7. Summary

Chapter 15: Deployment, Security, and Best Practices

  1. Deployment Architectures and Patterns
  2. Model Security and Protection
  3. Privacy Considerations in Browser ML
  4. Interoperability with Other ML Ecosystems
  5. Testing Machine Learning Code
  6. The Future of TensorFlow.js
  7. Summary

Conclusion

Glossary

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub