SSD icon indicating copy to clipboard operation
SSD copied to clipboard

How to use tensordboard?

Open githubyaww opened this issue 4 years ago • 5 comments

I want to look at the network structure diagram, but I am not sure how to change it,and i don't know how to use tensorboard, can you help me?

githubyaww avatar Mar 05 '21 09:03 githubyaww

Add this in the training code

from torch.utils.tensorboard import SummaryWriter

tboard_writer = SummaryWriter(log_dir="experiments")

# to add the network structure in the tensorboard logger
# make sure the type matches the input type required for the model
_dummy_input = torch.ones([1, c, h, w], dtype=torch.float32).to(self.device)
 tboard_writer.add_graph(self.model, _dummy_input)

# to add a batch of images in the tensorboard logger
tboard_writer.add_images('preprocessed image batch',
                                          next(iter(train_data_loader))[0],
                                          epoch_number)

# to add scalars such as loss/accuracy values in the tensorboard logger
tboard_writer.add_scalars('Loss (epoch)',
                                           {'train': train_loss},
                                           epoch_number)

Install tensorboard using pip, i.e. pip install tensorboard, then to run the tensorboard display on localhost:port 6006, run:

$ tensorboard --logdir=experiments --port=6006

More instructions here at the official PyTorch documentation

SamSamhuns avatar Apr 29 '21 12:04 SamSamhuns

Add this in the training code

from torch.utils.tensorboard import SummaryWriter

tboard_writer = SummaryWriter(log_dir="experiments")

# to add the network structure in the tensorboard logger
# make sure the type matches the input type required for the model
_dummy_input = torch.ones([1, c, h, w], dtype=torch.float32).to(self.device)
 tboard_writer.add_graph(self.model, _dummy_input)

# to add a batch of images in the tensorboard logger
tboard_writer.add_images('preprocessed image batch',
                                          next(iter(train_data_loader))[0],
                                          epoch_number)

# to add scalars such as loss/accuracy values in the tensorboard logger
tboard_writer.add_scalars('Loss (epoch)',
                                           {'train': train_loss},
                                           epoch_number)

Install tensorboard using pip, i.e. pip install tensorboard, then to run the tensorboard display on localhost:port 6006, run:

$ tensorboard --logdir=experiments --port=6006

More instructions here at the official PyTorch documentation

hello,i met this problem could you help me? NameError: name 'c' is not defined

bellzhong677 avatar Jul 01 '21 13:07 bellzhong677

c, h, w refer to the input channel, height and width of network. Based on what network you are using these values might be 3, 320, 320.

Check the config/yaml files to get the input shape of the network. For example this network mobilenet_v2_ssd320_voc0712.yaml will have c,h,w values of 3,320,320

SamSamhuns avatar Jul 01 '21 13:07 SamSamhuns

c, h, w refer to the input channel, height and width of network. Based on what network you are using these values might be 3, 320, 320.

Check the config/yaml files to get the input shape of the network. For example this network mobilenet_v2_ssd320_voc0712.yaml will have c,h,w values of 3,320,320

Thank you the code is work. But I still don't know in $ tensorboard --logdir=experiments --port=6006 What is the experiments

bellzhong677 avatar Jul 01 '21 14:07 bellzhong677

This line tboard_writer = SummaryWriter(log_dir="experiments") should create an experiments folder in your working directory where tensorboard stores its log files.

Then from a different terminal, you can enter tensorboard --logdir=experiments --port=6006 to start the tensorboard server in your localhost at port 6006, after which you can go to http://localhost:6006/ in your browser to see the tboard logs

SamSamhuns avatar Jul 04 '21 08:07 SamSamhuns