Open DerThorsten opened 5 years ago
of course this could be integrated more deeply into the inferno trainer.
This would also allow to support the log_scalars_every(1, 'epoch'))
syntax.
I'll impl that soonish
Update:
Set summary writer up:
trainer = Trainer(model)
trainer.setup_tensorboard_summary_writer(
log_directory=out_dir,
add_scalars_every=(1, 'iteration'),
add_embedding_every=(1, 'epoch')
)
Use summary writer from everywhere
# get logger instance at the top of file
from inferno.trainers.basic import Trainer
tb_logger = Trainer.tensorboard_summary_writer()
class MyLoss(nn.Module):
def forward(self, output, targets):
rec, mu, logvar = output
y_rec,y_labels = targets
as_img = y_rec.view([-1, 1, 28, 28])
as_img = as_img.repeat([1,3,1,1])
# log fancy embeddings
tb_logger.add_embedding(mu, metadata=y_labels, label_img=as_img)
rec_loss = self.rec_loss(rec, y_rec)
kld = -0.5 * torch.sum(1 + logvar - mu.pow(2) - logvar.exp())
scaled_kld = 0.01*kld
total = rec_loss + scaled_kld
# log fancy scalars
tb_logger.add_scalars('loss', {
'rec_loss':rec_loss,
'kld':kld,
'scaled_kld':scaled_kld,
'total':total
})
return total
The logger/writer supports all tensorboardx calls
add_audio
add_custom_scalars
add_custom_scalars_marginchart
add_custom_scalars_multilinechart
add_figure
add_graph
add_histogram
add_histogram_raw
add_hparams
add_image
add_mesh
add_pr_curve
add_pr_curve_raw
add_scalar
add_scalars
add_text
add_video
add_embedding
!Outdated, see latest comments! This Pr adds a different more flexible way to use the tensorboard logger. the usage after this pr is the following the logger is a singleton which can accessed in every header:
The logger needs to be set up bevor calling
trainer.fit
With that we can use the tensorboard logger inside every module / piece of code. This allows the very coolest usages of the tensorboard logger. For example:
Here is some complete example in usage: The interesting part is mostly in the loss function
I am rather new to the usage of tensorboard, but find this approach way more flexible as the one currently implemented in inferno . Those of you using the tensorboard features more frequently (@Steffen-Wolf @nasimrahaman @constantinpape ), what do you think of this approach?