TensorBoard is a suite of web applications for inspecting and understanding your TensorFlow runs and graphs
TensorBoard's program interface provides command-line application functionality and server management capabilities. It includes the main TensorBoard application class, server abstractions, and process lifecycle management for running TensorBoard instances.
The core TensorBoard application that handles configuration, plugin loading, and server lifecycle.
class TensorBoard:
"""
Main TensorBoard application class.
Handles server configuration, plugin management, and application lifecycle.
"""
def __init__(self, plugins=None, assets_zip_provider=None, server_class=None):
"""
Initialize TensorBoard application.
Args:
plugins (list, optional): List of plugin instances to load
assets_zip_provider (callable, optional): Provider for static assets
server_class (class, optional): Custom server implementation class
"""
def configure(self, **kwargs):
"""
Configure the TensorBoard application.
Args:
**kwargs: Configuration options including:
- logdir (str): Path to log directory
- port (int): Server port number
- host (str): Server host address
- reload_interval (int): Log reload interval in seconds
- max_reload_threads (int): Maximum reload thread count
- path_prefix (str): URL path prefix
- window_title (str): Browser window title
"""
def main(self, argv=None):
"""
Main entry point for command-line usage.
Args:
argv (list, optional): Command-line arguments. If None, uses sys.argv
Returns:
int: Exit code (0 for success, non-zero for error)
"""
def launch(self):
"""
Launch the TensorBoard server.
Starts the web server and begins serving TensorBoard interface.
This method blocks until the server is stopped.
"""Abstract base classes for implementing custom TensorBoard servers.
class TensorBoardServer:
"""
Abstract base class for TensorBoard server implementations.
Defines the interface that server implementations must provide.
"""
def serve_forever(self):
"""
Abstract method to start serving and block until stopped.
Must be implemented by subclasses to provide server functionality.
"""
class WerkzeugServer(TensorBoardServer):
"""
Default Werkzeug-based server implementation.
Provides threaded WSGI server functionality using Werkzeug.
"""Framework for extending TensorBoard with additional subcommands.
class TensorBoardSubcommand:
"""
Abstract base class for TensorBoard subcommands.
Enables extending TensorBoard with additional command-line functionality.
"""
def run(self, args, unknown_args):
"""
Abstract method to execute the subcommand.
Args:
args: Parsed command-line arguments
unknown_args: Unparsed command-line arguments
Must be implemented by subclasses.
"""Exception classes for server-related errors.
class TensorBoardServerException(Exception):
"""Base exception class for server-related errors."""
class TensorBoardPortInUseError(TensorBoardServerException):
"""Exception raised when the requested port is already in use."""Helper functions for enhanced server functionality.
def with_port_scanning(cls):
"""
Class decorator that adds port scanning functionality.
Args:
cls: Server class to decorate
Returns:
Decorated class with automatic port scanning when primary port is unavailable
"""from tensorboard.program import TensorBoard
# Create and configure TensorBoard
tb = TensorBoard()
tb.configure(
logdir='./logs',
port=6006,
host='localhost',
reload_interval=30
)
# Launch the server (blocks until stopped)
tb.launch()import sys
from tensorboard.program import TensorBoard
# Create TensorBoard instance
tb = TensorBoard()
# Run as command-line application
exit_code = tb.main(sys.argv[1:])
sys.exit(exit_code)from tensorboard.program import TensorBoard
from tensorboard.plugins.scalar import scalars_plugin
from tensorboard.plugins.histogram import histograms_plugin
# Configure with specific plugins
plugins = [
scalars_plugin.ScalarsPlugin(),
histograms_plugin.HistogramsPlugin()
]
tb = TensorBoard(plugins=plugins)
tb.configure(logdir='./logs', port=6006)
tb.launch()from tensorboard.program import TensorBoard, WerkzeugServer
# Use custom server class
tb = TensorBoard(server_class=WerkzeugServer)
tb.configure(
logdir='./multi_run_logs',
port=6007,
host='0.0.0.0', # Accept connections from any host
path_prefix='/tensorboard', # Serve under URL prefix
window_title='ML Experiment Dashboard',
max_reload_threads=10
)
tb.launch()from tensorboard.program import TensorBoard, TensorBoardPortInUseError
tb = TensorBoard()
tb.configure(logdir='./logs', port=6006)
try:
tb.launch()
except TensorBoardPortInUseError:
print("Port 6006 is already in use")
# Try alternative port
tb.configure(port=6007)
tb.launch()
except KeyboardInterrupt:
print("TensorBoard stopped by user")from tensorboard.program import TensorBoard, with_port_scanning
# Automatically scan for available ports if primary port is busy
@with_port_scanning
class AutoPortTensorBoard(TensorBoard):
pass
tb = AutoPortTensorBoard()
tb.configure(logdir='./logs', port=6006) # Will try 6006, 6007, 6008, etc.
tb.launch()The program interface provides the foundation for TensorBoard's command-line functionality and server management, enabling both standalone usage and integration into larger applications or workflows.
Install with Tessl CLI
npx tessl i tessl/pypi-tensorboard