wandb_tsbw
A compatibility layer for TensorBoard's SummaryWriter to log to Weights & Biases.
Description
wandb_tsbw provides a drop-in replacement for TensorBoard's SummaryWriter that logs to Weights & Biases (W&B) instead. This allows users to easily migrate from TensorBoard to W&B without changing their existing code.
Installation
pip install wandb_tsbw
Requirements
- Python >= 3.6
- wandb >= 0.12.0
- numpy >= 1.19.0
Usage
Simply replace your TensorBoard import with the wandb_tsbw import:
# Original TensorBoard code:
# from torch.utils.tensorboard import SummaryWriter
# New W&B-based code:
from wandb_tsbw import SummaryWriter
# Rest of your code remains the same
writer = SummaryWriter(log_dir='./runs/experiment_1')
writer.add_scalar('loss', 0.5, global_step=1)
# Pass W&B specific parameters through wandb_kwargs
writer = SummaryWriter(
log_dir='./runs/experiment_1',
wandb_kwargs={
'project': 'my_project',
'entity': 'my_team',
'tags': ['experiment', 'classification'],
'group': 'model_v1'
}
)
Features
The SummaryWriter class implements the same interface as TensorBoard's SummaryWriter but sends all data to W&B. It supports:
- Scalar logging
- Multiple scalars logging
- Histogram logging
- Image logging
- Text logging
- Figure logging (Matplotlib)
- Hyperparameter logging
- PR curve logging
- Embedding visualization
- Audio logging
- Video logging
Differences from TensorBoard
While wandb_tsbw attempts to provide a drop-in replacement for TensorBoard's SummaryWriter, there are some subtle differences:
- W&B requires authentication. Make sure you've run
wandb loginbefore using this package. - W&B has different visualization capabilities, so some visualizations may look different.
- W&B automatically syncs data to their cloud servers, while TensorBoard keeps data locally.
- Some advanced TensorBoard features (like debugging) may not be fully supported.
Example
import torch
import torch.nn.functional as F
from wandb_tsbw import SummaryWriter
import numpy as np
# Initialize the SummaryWriter
writer = SummaryWriter(log_dir='runs/experiment_1')
# Log scalars
for i in range(10):
writer.add_scalar('Loss/train', np.random.random(), i)
writer.add_scalar('Loss/test', np.random.random(), i)
writer.add_scalar('Accuracy/train', np.random.random(), i)
writer.add_scalar('Accuracy/test', np.random.random(), i)
# Log histogram
writer.add_histogram('Conv1.bias', torch.randn(100), 0)
# Log image
img = torch.zeros(3, 100, 100) # C, H, W
img[0] = torch.arange(0, 10000).reshape(100, 100) / 10000
writer.add_image('Example Image', img, 0)
# Log text
writer.add_text('Text Example', 'Hello World!', 0)
# Log hyperparameters
writer.add_hparams(
{'lr': 0.1, 'batch_size': 64},
{'accuracy': 0.9, 'loss': 0.2}
)
# Close the writer
writer.close()
Debugging:
Option 1: Use pytest's command line option
Run pytest with the --trace option to drop into the debugger at the start of each test:
pytest-3 tests/test_writer.py::TestSummaryWriter::test_add_hparams --trace
Option 4: Debug on test failure
You can configure pytest to automatically start the debugger when a test fails:
pytest-3 tests/test_writer.py -v --pdb
License
MIT
Metadata
Release files for wandb-tsbw 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wandb_tsbw-0.1.0.tar.gz | 11.0 kB | Without provenance | Details for wandb_tsbw-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wandb_tsbw-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for wandb_tsbw-0.1.0-py3-none-any.whl |
Total release size: 20.9 kB
Release files / wandb_tsbw-0.1.0.tar.gz
| Download URL | wandb_tsbw-0.1.0.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc3430cd4047b1dbd3d41f056aafafc5e171bea8eb57cca0d2a914574f2e1ec9
|
|
BLAKE2b-256 checksum How to use checksums |
205243cde1544b9f0c179d6c8ea231907a1ef5f0e153cbaf4248697f6891fe8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Release files / wandb_tsbw-0.1.0-py3-none-any.whl
| Download URL | wandb_tsbw-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4dd1e80efb5663fdb70e85d8f8478c496f948f96df0211f6b02ba5dda5d3ef4a
|
|
BLAKE2b-256 checksum How to use checksums |
cbece3385254005cd3b2358c8c8cd0372518fbcf1205c2df34d14ec6bba6789d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.12
|
Security for wandb-tsbw 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.