Chapter 23: TensorFlow.js Visor

Step 1: What Exactly is the TensorFlow.js Visor?

TensorFlow.js Visor (or tfjs-vis Visor) is a small, in-browser visualization library (called @tensorflow/tfjs-vis) designed specifically to work with TensorFlow.js.

Its main job:

  • Show live graphs, charts, tables, and other visuals inside your web page (or in a separate floating panel) while your model trains or runs.
  • Help you understand what your model is doing — loss curves, accuracy over time, confusion matrices, sample predictions, data distributions, weight histograms, etc.
  • Keep visualizations organized and non-intrusive — they don’t mess up your main app UI.

The Visor itself is a singleton UI panel (a floating window or tabbed interface) that tfjs-vis creates automatically. You call functions like tfvis.show.fitCallbacks() or tfvis.visor().surface() to send visuals to it.

Key features (still relevant in 2026):

  • Live training monitoring (loss/accuracy plots that update every epoch)
  • Data visualization (scatter plots, histograms of your dataset)
  • Model inspection (confusion matrix, prediction tables)
  • Custom surfaces (place charts/tables anywhere on page or in Visor)
  • Works entirely in browser — no server needed

It’s lightweight (~100–200 KB minified) and uses libraries like d3.js under the hood for rendering.

Important 2026 note: tfjs-vis was a separate repo but has been archived and integrated/maintained within the main TensorFlow.js ecosystem. You still install it via npm or CDN, and it works great with the latest tfjs.

Step 2: Why Use the Visor? (Real-Life Analogy)

Imagine you’re teaching a child (your model) to recognize handwritten Telugu digits (0–9 like in MNIST).

  • Without Visor: You train for 10 epochs → only see final accuracy in console → “Did it improve? Was it overfitting? What went wrong?”
  • With Visor: Every epoch, a nice graph pops up showing loss dropping, accuracy rising → you watch live like a progress chart → spot if loss explodes or plateaus → see sample predictions (good/bad) → understand the learning process.

It’s like having a live dashboard for your ML training — makes debugging 10× easier and more fun!

Step 3: How to Set It Up (Super Easy)

Two ways:

  1. CDN (quick demos):
HTML
  1. NPM (real projects):
Bash
JavaScript

Step 4: Classic Example – Training with Live Visor Graphs

This is the most common use: monitor loss & accuracy during training.

Full HTML file — copy-paste and open in browser:

HTML

What happens when you run this:

  • Click button → training starts
  • A floating Visor panel appears (or new tab if you prefer)
  • Inside Visor: Live line chart of loss dropping over epochs
  • You see the model learning in real-time — beautiful!

Step 5: More Cool tfjs-vis Features (Quick Examples)

  1. Scatter Plot of Data
JavaScript
  1. Confusion Matrix (after classification)
JavaScript
  1. Custom Surface (place chart anywhere)
JavaScript

Step 6: Quick Summary Table

Feature What It Does How to Use Why Useful in 2026
Visor Panel Floating/tabbed window for all visuals tfvis.visor() Keeps UI clean, non-intrusive
fitCallbacks Auto-plots loss/accuracy during .fit() tfvis.show.fitCallbacks(surface, [‘loss’]) Live training monitoring
Scatterplot Plot data points tfvis.render.scatterplot(…) Visualize dataset before training
Confusion Matrix Show classification errors tfvis.show.perClassAccuracy(…) Debug model mistakes
Custom Surfaces Place charts/tables anywhere tfvis.visor().surface(…) Flexible for complex apps

Final Teacher Words

TensorFlow.js Visor (from tfjs-vis) = your best friend for visualizing what’s happening inside TensorFlow.js models in the browser.

  • No more staring at console logs — see beautiful live graphs!
  • Great for learning, debugging, demos, teaching ML in web apps.

In 2026: Still the go-to tool for tfjs visualization — lightweight, no extra servers, and integrates perfectly with training loops.

Got it now? 🔥

Questions?

  • Want code for confusion matrix on MNIST?
  • How to open Visor in new tab only?
  • tfjs-vis vs other viz libs (Chart.js)?

Just ask — class is open! 🚀

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *