TensorBoardX lets you watch Tensors Flow without Tensorflow
npx @tessl/cli install tessl/pypi-tensorboardx@2.6.0TensorBoardX lets you watch Tensors Flow without TensorFlow. A Python library that provides TensorBoard event logging capabilities without requiring TensorFlow, enabling visualization of machine learning experiments through simple function calls. Supports comprehensive visualization types including scalars, images, figures, histograms, audio, text, computational graphs, ONNX graphs, embeddings, precision-recall curves, 3D meshes, hyperparameters, and videos.
pip install tensorboardXpip install crc32c (for speed), pip install soundfile (for audio)from tensorboardX import SummaryWriterMultiple classes available:
from tensorboardX import (
SummaryWriter, # Main writer class
FileWriter, # Low-level protocol buffer writer
GlobalSummaryWriter, # Thread-safe writer with auto-incrementing steps
RecordWriter, # Low-level TensorFlow record format writer
TorchVis # Multi-backend visualization (TensorBoard + Visdom)
)from tensorboardX import SummaryWriter
import numpy as np
# Create a SummaryWriter
writer = SummaryWriter('runs/experiment_1')
# Log scalar values
for step in range(100):
loss = np.random.random()
accuracy = np.random.random()
writer.add_scalar('Loss/Train', loss, step)
writer.add_scalar('Accuracy/Train', accuracy, step)
# Log images, histograms, and other data types
dummy_img = np.random.rand(3, 64, 64) # CHW format
writer.add_image('Sample_Image', dummy_img, step)
# Close the writer
writer.close()
# View in TensorBoard
# tensorboard --logdir=runsTensorBoardX provides multiple writer classes with different capabilities:
The library integrates seamlessly with PyTorch, NumPy, and other ML frameworks while maintaining compatibility with TensorBoard's visualization ecosystem.
Main high-level writer class providing comprehensive logging capabilities for scalars, media, graphs, embeddings, and advanced visualizations with automatic file management and flexible configuration options.
class SummaryWriter:
def __init__(
self,
logdir: Optional[str] = None,
comment: Optional[str] = "",
purge_step: Optional[int] = None,
max_queue: Optional[int] = 10,
flush_secs: Optional[int] = 120,
filename_suffix: Optional[str] = '',
write_to_disk: Optional[bool] = True,
log_dir: Optional[str] = None,
comet_config: Optional[dict] = {"disabled": True}
): ...
def add_scalar(self, tag: str, scalar_value, global_step: Optional[int] = None, walltime: Optional[float] = None): ...
def add_image(self, tag: str, img_tensor, global_step: Optional[int] = None, walltime: Optional[float] = None): ...
def add_graph(self, model, input_to_model=None, verbose=False): ...
def close(self): ...Low-level protocol buffer writer for direct event file control, providing fine-grained management of TensorBoard event files with manual summary and event handling.
class FileWriter:
def __init__(self, logdir: str, max_queue: int = 10, flush_secs: int = 120, filename_suffix: str = ''): ...
def add_event(self, event, step=None, walltime=None): ...
def add_summary(self, summary, global_step=None, walltime=None): ...
def get_logdir(self) -> str: ...
def flush(self): ...
def close(self): ...Thread-safe writer with automatic step incrementing for concurrent logging across processes, simplifying multi-threaded experiment tracking without manual step management.
class GlobalSummaryWriter:
def __init__(
self,
logdir: Optional[str] = None,
comment: str = '',
purge_step: Optional[int] = None,
max_queue: int = 10,
flush_secs: int = 120,
filename_suffix: str = '',
write_to_disk: bool = True,
log_dir: Optional[str] = None,
coalesce_process: bool = True
): ...
def add_scalar(self, tag: str, scalar_value, walltime: Optional[float] = None): ...
def add_image(self, tag: str, img_tensor, walltime: Optional[float] = None): ...
@staticmethod
def getSummaryWriter() -> 'GlobalSummaryWriter': ...Multi-backend visualization class supporting both TensorBoard and Visdom simultaneously, enabling cross-platform experiment monitoring and visualization comparison.
class TorchVis:
def __init__(self, *args, **init_kwargs): ...
def register(self, *args, **init_kwargs): ...
def unregister(self, *args): ...
# All SummaryWriter methods available through dynamic proxyLow-level TensorFlow record format writer for direct binary record writing with support for local filesystem, Amazon S3, and Google Cloud Storage backends.
class RecordWriter:
def __init__(self, path: str): ...
def write(self, data: bytes): ...
def flush(self): ...
def close(self): ...Data conversion and tensor processing utilities for preparing data for TensorBoard visualization, including format conversion, figure handling, and tensor manipulation.
def figure_to_image(figures, close: bool = True): ...
def make_np(x): ...
def convert_to_HWC(tensor, input_format: str): ...
def convert_to_NTCHW(tensor, input_format: str): ...