analogvnn.utils.TensorboardModelLog#

Module Contents#

Classes#

TensorboardModelLog

Tensorboard model log.

class analogvnn.utils.TensorboardModelLog.TensorboardModelLog(model: analogvnn.nn.module.Model.Model, log_dir: str)[source]#

Tensorboard model log.

Variables:
  • model (nn.Module) – the model to log.

  • tensorboard (SummaryWriter) – the tensorboard.

  • layer_data (bool) – whether to log the layer data.

  • _log_record (Dict[str, bool]) – the log record.

model: torch.nn.Module[source]#
tensorboard: Optional[torch.utils.tensorboard.SummaryWriter][source]#
layer_data: bool[source]#
_log_record: Dict[str, bool][source]#
__exit__[source]#

Close the tensorboard.

set_log_dir(log_dir: str) TensorboardModelLog[source]#

Set the log directory.

Parameters:

log_dir (str) – the log directory.

Returns:

self.

Return type:

TensorboardModelLog

Raises:

ValueError – if the log directory is invalid.

_add_layer_data(epoch: int = None)[source]#

Add the layer data to the tensorboard.

Parameters:

epoch (int) – the epoch to add the data for.

on_compile(layer_data: bool = True)[source]#

Called when the model is compiled.

Parameters:

layer_data (bool) – whether to log the layer data.

add_graph(train_loader: torch.utils.data.DataLoader, model: Optional[torch.nn.Module] = None, input_size: Optional[Sequence[int]] = None) TensorboardModelLog[source]#

Add the model graph to the tensorboard.

Parameters:
  • train_loader (DataLoader) – the train loader.

  • model (Optional[nn.Module]) – the model to log.

  • input_size (Optional[Sequence[int]]) – the input size.

Returns:

self.

Return type:

TensorboardModelLog

add_summary(input_size: Optional[Sequence[int]] = None, train_loader: Optional[torch.utils.data.DataLoader] = None, model: Optional[torch.nn.Module] = None, *args, **kwargs) Tuple[str, str][source]#

Add the model summary to the tensorboard.

Parameters:
  • input_size (Optional[Sequence[int]]) – the input size.

  • train_loader (Optional[DataLoader]) – the train loader.

  • model (nn.Module) – the model to log.

  • *args – the arguments to torchinfo.summary.

  • **kwargs – the keyword arguments to torchinfo.summary.

Returns:

the model __repr__ and the model summary.

Return type:

Tuple[str, str]

register_training(epoch: int, train_loss: float, train_accuracy: float) TensorboardModelLog[source]#

Register the training data.

Parameters:
  • epoch (int) – the epoch.

  • train_loss (float) – the training loss.

  • train_accuracy (float) – the training accuracy.

Returns:

self.

Return type:

TensorboardModelLog

register_testing(epoch: int, test_loss: float, test_accuracy: float) TensorboardModelLog[source]#

Register the testing data.

Parameters:
  • epoch (int) – the epoch.

  • test_loss (float) – the test loss.

  • test_accuracy (float) – the test accuracy.

Returns:

self.

Return type:

TensorboardModelLog

close(*args, **kwargs)[source]#

Close the tensorboard.

Parameters:
  • *args – ignored.

  • **kwargs – ignored.

__enter__()[source]#

Enter the TensorboardModelLog context.

Returns:

self.

Return type:

TensorboardModelLog