lufficc / SSD

High quality, fast, modular reference implementation of SSD in PyTorch
MIT License
1.51k stars 385 forks source link

How to use tensordboard? #195

Open githubyaww opened 3 years ago

githubyaww commented 3 years ago

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?

SamSamhuns commented 3 years ago

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

bellzhong677 commented 3 years ago

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

SamSamhuns commented 3 years ago

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

bellzhong677 commented 3 years ago

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

SamSamhuns commented 3 years ago

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