You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# demo.pyimporttorchimporttorchvision.utilsasvutilsimportnumpyasnpimporttorchvision.modelsasmodelsfromtorchvisionimportdatasetsfromtensorboardXimportSummaryWriterresnet18=models.resnet18(False)
writer=SummaryWriter()
sample_rate=44100freqs= [262, 294, 330, 349, 392, 440, 440, 440, 440, 440, 440]
forn_iterinrange(100):
dummy_s1=torch.rand(1)
dummy_s2=torch.rand(1)
# data grouping by `slash`writer.add_scalar('data/scalar1', dummy_s1[0], n_iter)
writer.add_scalar('data/scalar2', dummy_s2[0], n_iter)
writer.add_scalars('data/scalar_group', {'xsinx': n_iter*np.sin(n_iter),
'xcosx': n_iter*np.cos(n_iter),
'arctanx': np.arctan(n_iter)}, n_iter)
dummy_img=torch.rand(32, 3, 64, 64) # output from networkifn_iter%10==0:
x=vutils.make_grid(dummy_img, normalize=True, scale_each=True)
writer.add_image('Image', x, n_iter)
dummy_audio=torch.zeros(sample_rate*2)
foriinrange(x.size(0)):
# amplitude of sound should in [-1, 1]dummy_audio[i] =np.cos(freqs[n_iter//10] *np.pi*float(i) /float(sample_rate))
writer.add_audio('myAudio', dummy_audio, n_iter, sample_rate=sample_rate)
writer.add_text('Text', 'text logged at step:'+str(n_iter), n_iter)
forname, paraminresnet18.named_parameters():
writer.add_histogram(name, param.clone().cpu().data.numpy(), n_iter)
# needs tensorboard 0.4RC or laterwriter.add_pr_curve('xoxo', np.random.randint(2, size=100), np.random.rand(100), n_iter)
dataset=datasets.MNIST('mnist', train=False, download=True)
images=dataset.test_data[:100].float()
label=dataset.test_labels[:100]
features=images.view(100, 784)
writer.add_embedding(features, metadata=label, label_img=images.unsqueeze(1))
# export scalar data to JSON for external processingwriter.export_scalars_to_json("./all_scalars.json")
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