tensorboardX

repository·master·Indexed 27 days ago

https://github.com/lanpa/tensorboardx

A lightweight library that allows users to write TensorBoard events using simple function calls without requiring TensorFlow. It provides the SummaryWriter and GlobalSummaryWriter classes to log various data types, including scalars, images, histograms, audio, text, and embeddings, for visualizing machine learning training progress. It also supports direct integration with Comet for cloud-based experiment tracking.

Tokens
8.7K
Snippets
23
Records
84
Agent score
92%

What's inside tensorboardX

  1. Install tensorboardX

    master

    You can install tensorboardX via pip or build it from the source repository.

    To improve performance, it is recommended to install crc32c. Additionally, for the add_audio() function, you must install soundfile (which provides a 200x speedup).

  2. Run local tests for TensorBoardX

    master

    You can run the project's test suite using the provided helper script or manually via pytest. If using uv, ensure you have pinned setuptools as described in the environment setup.

    # Quick Start using the helper script
    ./run_pytest.sh
    
    # Manual testing with uv
    uv pip install "setuptools==81.0.0"
    uv run pytest
  3. Install tensorboardX and Tensorboard

    master

    To use tensorboardX, install it via pip. To visualize the logs, you must also install the tensorboard web server.

    # Install tensorboardX
    pip install tensorboardX
    
    # Install the tensorboard web server
    pip install tensorboard
    pip install tensorboardX
    pip install tensorboard
  4. Integrate tensorboardX with Comet

    master
    TensorboardX supports logging directly to Comet, a cloud-based experiment tracking solution. This integration works out of the box and allows you to use Comet's advanced features like dataset management and experiment diffing on top of your TensorBoard logs.
  5. Use SummaryWriter to log data

    master

    The SummaryWriter class is the primary interface for writing TensorBoard events. It supports various summary types including scalar, image, figure, histogram, audio, text, graph, onnx_graph, embedding, pr_curve, mesh, hyper-parameters, and video.

    Key usage patterns:

    • Data Grouping: Use forward slashes (/) in tag names to group data in the TensorBoard UI (e.g., 'data/scalar1').
    • Multiple Scalars: Use add_scalars to plot multiple series in the same chart.
    • Audio Requirements: When using add_audio(), ensure the audio amplitude is within the range [-1, 1] and install soundfile for optimal performance.
    • PR Curves: add_pr_curve requires TensorBoard version 0.4RC or later.
  6. View results in TensorBoard

    master

    TensorBoard reads the event files written by tensorboardX. You must have tensorboard installed to view the results.

    1. Install TensorBoard: pip install tensorboard (the non-GPU version is recommended for faster startup if you don't need GPU support).
    2. Launch the server: Run the following command in your terminal, pointing to your log directory:
    tensorboard --logdir=runs
    1. Open Browser: Follow the terminal instructions to open the web interface in your browser.
  7. Set up the development environment for TensorBoardX

    master

    To avoid ModuleNotFoundError caused by the removal of pkg_resources in newer versions of setuptools, you must pin setuptools to version 81.0.0 or earlier during local development and testing. The project uses setuptools_scm to derive its version dynamically from the most recent git tag.

    uv pip install "setuptools==81.0.0"
  8. Initialize SummaryWriter

    master

    To record data, you must first create a SummaryWriter instance. The SummaryWriter class contains all the functionality of the package.

    • With a specific directory: SummaryWriter('runs/exp-1') saves data to runs/exp-1.
    • With default settings: SummaryWriter() saves data to a directory named after the current time and machine name (e.g., runs/Aug20-obov01).
    • With a comment: SummaryWriter(comment='3xLR') appends a comment to the default directory name (e.g., runs/Aug20-obov01-3xLR).

    Each subdirectory within the runs folder is treated as a separate experiment. It is recommended to use unique names (like timestamps or parameter names) for each experiment to facilitate comparison.