TensorBoard Logger - no self.experiment?

I’m trying to log a confusion matrix that I can view in tensorboard.

I’ve defined my class as a pytorch lightning module.

class BiasClassifier(pl.LightningModule): 
   ...

I’m looking at the lightning module properties here as well as the trainer logging docs here under tensorboard support. Both access self.experiment on (what I believe to be) a lightning module.

When I try to call self.experiment in my BiasClassifier, I get an error.

torch.nn.modules.module.ModuleAttributeError: 'BiasClassifier' object has no attribute 'experiment'

Is there another way I need to access the summary writer? Or a better way for me to log an image of the confusion matrix after every training epoch? Something wrong with my class declaration?

For more info, here is my call

    model = BiasClassifier()
    trainer = pl.Trainer(
        default_root_dir='logs',
        gpus=(1 if th.cuda.is_available() else 0),
        max_epochs=25,
        fast_dev_run=True, 
        logger=pl.loggers.TensorBoardLogger('logs/', name='debug', version=0),
    )
    trainer.fit(model)

Looks like you may have to call self.logger.experiment instead of just self.experiment like the documentation had me believing. Hope this helps someone else!

1 Like