Skip to main content

A wrapper for TensorBoard SummaryWriter with real-time terminal visualization using the Rich library.

Project description

GraphWriter

GraphWriter is a robust, interactive, and visually appealing wrapper for TensorBoard's SummaryWriter, designed to provide real-time insights into your machine learning model's performance right in your terminal. It uses the Rich library to render elegant visualizations, progress bars, and logs, thus turning your mundane terminal into a vibrant dashboard.

demo

Features

  • Real-time scalar plots for training and testing metrics.
  • Progress bars for iterable processes such as epochs and batches.
  • Customizable console print function to log insights in a structured manner.
  • Grouping of scalars based on prefixes for organized visualization.
  • Colorful and lively terminal output, making the model training process more interactive and insightful.

Installation

The project requires torch, rich, and asciichartpy libraries to be installed in your python environment.

pip install graphWriter

Example

You can run the example script to see the GraphWriter in action.

python -m graphWriter.graphWriter

Usage

from torch.utils.tensorboard import SummaryWriter
from graphWriter import GraphWriter
import math
import random

# Initialize Tensorboard SummaryWriter
writer = SummaryWriter()

# Create an instance of GraphWriter
graph_writer = GraphWriter(writer)

# Simulate a training and testing process
for e in graph_writer.track(range(100), description="epochs"):
    for t in graph_writer.track(range(100), description="training"):
        # Simulated metrics
        train_loss = 3*math.exp(-0.1*e + 0.1*random.gauss(0, 1))
        train_acc =  100 - 20 * math.exp(-1.5*e/30) - random.randrange(0, 90)/(e+1)

        # Log metrics
        graph_writer.add_scalar('Train/Loss', train_loss, global_step=t + e*100)
        graph_writer.add_scalar('Train/Acc', train_acc, global_step=t + e*100)

    for t in graph_writer.track(range(100), description="testing"):
        # Simulated metrics
        test_loss = 2*math.exp(-0.1*e+ 0.2*random.gauss(0, 1))
        test_acc =  100 - 20 * math.exp(-2.0*e/30) - random.randrange(0, 90)/(e+1)

        # Log metrics
        graph_writer.add_scalar('Test/Loss', test_loss, global_step=t + e*100)
        graph_writer.add_scalar('Test/Acc', test_acc, global_step=t + e*100)

    graph_writer.add_scalar('Epochs', e, global_step=e)
    graph_writer.print(f"Epoch [green]{e}[/green] completed!")
# close the writer
writer.close()

The GraphWriter class is initialized with a SummaryWriter object, along with optional arguments for setting the maximum number of lines for print statements and progress bars. The add_scalar method is used to log scalar values to TensorBoard, and the track method is utilized to create progress bars for iterable processes.

Methods

Here's a brief overview of the primary methods available in the GraphWriter class:

  • add_scalar(tag, scalar_value, global_step=None, display=True): Logs a scalar value to TensorBoard and updates the scalar panel.
  • print(*args, **kwargs): A custom print function to display text in the print layout.
  • track(iterable, description="Processing..."): Yields items from an iterable and updates a progress bar.
  • update_scalars(tag): Updates the scalar panels with new data.
  • group_scalars_by_prefix(): Groups scalar layouts by their prefix for organized visualization.

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

MIT


This README provides a comprehensive overview of the GraphWriter project, its features, installation steps, usage examples, available methods, and contribution guidelines.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphWriter-0.5.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphWriter-0.5.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file graphWriter-0.5.2.tar.gz.

File metadata

  • Download URL: graphWriter-0.5.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for graphWriter-0.5.2.tar.gz
Algorithm Hash digest
SHA256 ce9a9995eb1490a17512de48056e1c702b97cf44d8e31093611600b8d158d6bc
MD5 8585d8b72b883ae4e27289a2eea34893
BLAKE2b-256 b6442153c4af87b40df9fff53c1ee12c23fbec536696727403a58153e6f0d169

See more details on using hashes here.

File details

Details for the file graphWriter-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: graphWriter-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for graphWriter-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29d7e4da8f5d19c2c4b041be0c8b19f4925752f265597b49bb6d155ec27fccac
MD5 6274ce6ac3e3d7c6ee939a467f67c96a
BLAKE2b-256 3f5f729376d01dfe5fe4f5bbd10850b635c8597b1e3eed73787481271190510e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page