metallic.utils

Logger

class metallic.utils.Logger(root: str, n_iters_per_epoch: int, log_basename: str = '', log_interval: int = 100, tensorboard: bool = False, verbose: bool = False)[source]

Bases: object

A loggger to log and visualize (based on Tensorboard) statistics.

Parameters
  • root (str) – Root directory of the log files

  • n_iters_per_epoch (int) – Number of the iterations per epoch

  • log_basename (str, optional, default='') – Base name of the log file

  • log_interval (int, optional, default=100) – Steps between info loggings

  • tensorboard (bool, optional, default=False) – Enable tensorboard or not (tensorboard package is required)

  • verbose (bool, optional, default=False) –

log(data: dict, epoch: int, i_iter: int, stage: str)None[source]

Log statistics generated during updating.

Parameters
  • data (dict) – Data to be logged

  • epoch (int) – Epoch of the data to be logged

  • i_iter (int) – Iteration of the data to be logged

  • stage (str) – Name of the current stage

write_tensorboard(key: str, x: numbers.Number, y: numbers.Number)None[source]

Log data into Tensorboard.

Parameters
  • key (str) – Namespace which the input data tuple belongs to

  • x (Union[Number, np.number]) – Ordinate of the input data

  • y (Union[Number, np.number]) – Abscissa of the input data

write_text(text: str)None[source]

Log data into text files.

Parameters

text (str) – A string to be logged

Metrics

class metallic.utils.MetricTracker(*names)[source]

Bases: object

Keep track of metrics.

add(name: str)None[source]

Add a new metric.

property metrics

Return a dict containing all metrics.

reset()None[source]

Clear all of the recorded metrics.

update(name: str, value: numbers.Number)None[source]

Update a new value to a specified metric.

metallic.utils.get_accuracy(scores: torch.Tensor, targets: torch.Tensor)float[source]

Compute accuracy using predicted scores and targets.