'Trying to use Tensorboard on Google Colab

The page below gives informations about Tensorboard: https://pytorch.org/docs/stable/tensorboard.html I am using Google Colab and when i write the following instructions(which are in the link above):

!pip install tensorboard
tensorboard --logdir=runs

it sends me the following error message:

 File "<ipython-input-111-949c7e8e565e>", line 2
tensorboard --logdir=runs
                         ^
SyntaxError: can't assign to operator

so when i copy paste their own example:

from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter()
x = range(100)
for i in x:
    writer.add_scalar('y=2x', i * 2, i)
writer.close()

it does not return the expected graph. Could someone help me fix this problem?Thank you in advance!



Solution 1:[1]

As explained in How to use Tensorboard with PyTorch in Google Colab.

In Google Colab you should start Tensorboard magic at the start of your code with:

%load_ext tensorboard

and after you define a summary file you need to insatiate Tensorboard with

%tensorboard --logdir $tensorboard_dir

where Tensorboard dir is a script variable of type str indicating where the summary file is.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ido Loebl