项目作者: lanpa

项目描述 :
pytorch的张量板(和chainer,mxnet,numpy,...)
高级语言: Python
项目地址: git://github.com/lanpa/tensorboardX.git
创建时间: 2017-06-13T13:54:19Z
项目社区:https://github.com/lanpa/tensorboardX

开源协议:MIT License

下载


tensorboardX

PyPI version
Documentation Status
Coverage Status

Write TensorBoard events with simple function call.

The current release (v2.6.3) is tested with PyTorch 2.6 / torchvision 0.21.0 / tensorboard 2.19.0 on Python 3.9 to 3.12

  • Support scalar, image, figure, histogram, audio, text, graph, onnx_graph, embedding, pr_curve, mesh, hyper-parameters
    and video summaries.

  • FAQ

Install

pip install tensorboardX

or build from source:

pip install 'git+https://github.com/lanpa/tensorboardX'

You can optionally install crc32c to speed up.

pip install crc32c

Starting from tensorboardX 2.1, You need to install soundfile for the add_audio() function (200x speedup).

pip install soundfile

Example

  1. # demo.py
  2. import torch
  3. import torchvision.utils as vutils
  4. import numpy as np
  5. import torchvision.models as models
  6. from torchvision import datasets
  7. from tensorboardX import SummaryWriter
  8. resnet18 = models.resnet18(False)
  9. writer = SummaryWriter()
  10. sample_rate = 44100
  11. freqs = [262, 294, 330, 349, 392, 440, 440, 440, 440, 440, 440]
  12. for n_iter in range(100):
  13. dummy_s1 = torch.rand(1)
  14. dummy_s2 = torch.rand(1)
  15. # data grouping by `slash`
  16. writer.add_scalar('data/scalar1', dummy_s1[0], n_iter)
  17. writer.add_scalar('data/scalar2', dummy_s2[0], n_iter)
  18. writer.add_scalars('data/scalar_group', {'xsinx': n_iter * np.sin(n_iter),
  19. 'xcosx': n_iter * np.cos(n_iter),
  20. 'arctanx': np.arctan(n_iter)}, n_iter)
  21. dummy_img = torch.rand(32, 3, 64, 64) # output from network
  22. if n_iter % 10 == 0:
  23. x = vutils.make_grid(dummy_img, normalize=True, scale_each=True)
  24. writer.add_image('Image', x, n_iter)
  25. dummy_audio = torch.zeros(sample_rate * 2)
  26. for i in range(x.size(0)):
  27. # amplitude of sound should in [-1, 1]
  28. dummy_audio[i] = np.cos(freqs[n_iter // 10] * np.pi * float(i) / float(sample_rate))
  29. writer.add_audio('myAudio', dummy_audio, n_iter, sample_rate=sample_rate)
  30. writer.add_text('Text', 'text logged at step:' + str(n_iter), n_iter)
  31. for name, param in resnet18.named_parameters():
  32. writer.add_histogram(name, param.clone().cpu().data.numpy(), n_iter)
  33. # needs tensorboard 0.4RC or later
  34. writer.add_pr_curve('xoxo', np.random.randint(2, size=100), np.random.rand(100), n_iter)
  35. dataset = datasets.MNIST('mnist', train=False, download=True)
  36. images = dataset.test_data[:100].float()
  37. label = dataset.test_labels[:100]
  38. features = images.view(100, 784)
  39. writer.add_embedding(features, metadata=label, label_img=images.unsqueeze(1))
  40. # export scalar data to JSON for external processing
  41. writer.export_scalars_to_json("./all_scalars.json")
  42. writer.close()

Screenshots

Using TensorboardX with Comet

TensorboardX now supports logging directly to Comet. Comet is a free cloud based solution that allows you to automatically track, compare and explain your experiments. It adds a lot of functionality on top of tensorboard such as dataset management, diffing experiments, seeing the code that generated the results and more.

This works out of the box and just require an additional line of code. See a full code example in this Colab Notebook



Tweaks

To add more ticks for the slider (show more image history), check https://github.com/lanpa/tensorboardX/issues/44 or
https://github.com/tensorflow/tensorboard/pull/1138

Reference