orcanet.logging

Scripts for writing the logfiles.

Module Contents

Classes

TrainfileLogger

SummaryLogger

For writing the summary logfile made during training.

BatchLogger

Write logfiles during training.

Functions

gen_line_str(data[, widths, seperator, ...])

Generate a line in nice human readable format,

gen_line_cells(data[, widths, float_precision, ...])

Generate the content of the cells for a line in the summary file.

merge_arrays(base, supp[, exclude])

Fill nans in a list with values from another list.

log_start_training(orga)

When a training is started for the first time, this logs all the

log_start_validation(orga)

Log filenames used for validation.

class orcanet.logging.TrainfileLogger(log_file, column_names)[source]
level_file()[source]

Make file with only the head lines.

Existing file will be overwritten.

write_line(values)[source]

Write a line with data to the file.

Parameters
valuesList

The data, in the same order as the column names.

orcanet.logging.gen_line_str(data, widths=None, seperator=' | ', float_precision=4, minimum_cell_width=9)[source]

Generate a line in nice human readable format, consisting of multiple spaced and seperated cells.

Parameters
datatuple

Strings or floats of what is in each cell. It must be in the same order and have the same length as the column names.

widthsList or None

Optional: The width of every cell. If None, will set it automatically, depending on the data. If widths is given, but what is given in data is wider than the width, the cell will expand without notice. Must have the same length as the column names.

seperatorstr

String that seperates two adjacent cells.

float_precisionint

Precision to which floats are rounded if they appear in data. The length of the resulting numbercan be up to 5 characters longer than this value (due to . and e-09)

minimum_cell_widthint

Minimum width of the cells in characters.

Returns
linestr

The line.

new_widthsList

The widths of the cells.

orcanet.logging.gen_line_cells(data, widths=None, float_precision=4, minimum_cell_width=9)[source]

Generate the content of the cells for a line in the summary file.

See gen_line_str (above) for doc.

Returns
cellsList
new_widthsList
class orcanet.logging.SummaryLogger(orga, model)[source]

For writing the summary logfile made during training.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

modelks.model.Model or None

Keras model containing the metrics to plot.

write_line(epoch_float, lr, history_train=None, history_val=None)[source]

Write a line to the summary.txt file in the trained model folder.

Will update an existing line if possible.

Parameters
epoch_floatfloat

The current epoch and fileno as a float.

lrfloat/str

The current learning rate of the model.

history_traindict

Dict containing the history of the training, averaged over files. Keys: Metric names, e.g. “loss”, “accuracy”, … Values: Value of the metric during validation as a float.

history_valdict or None

Dict of validation losses for all the metrics, averaged over all validation files. Keys: Metric names, e.g. “loss”, “accuracy”, … Values: Value of the metric during validation as a float.

Notes

In tf 2.2, model.metrics_names is only filled after the model has been used on data, i.e. only after that point this line can be run. Otherwise, _get_column_names will throw a NameError.

orcanet.logging.merge_arrays(base, supp, exclude=None)[source]

Fill nans in a list with values from another list.

Parameters
baseList
suppList
excludeList or int

Which indices to ignore.

Returns
np.array
class orcanet.logging.BatchLogger(orga, epoch, reset_metrics=True)[source]

Write logfiles during training.

Averages the losses of the model over some number of batches, and then writes that in a line in the logfile. The Batch_float entry in the logfiles gives the absolute position of the batch in the epoch (i.e. taking all files into account). This class is intended to be used only for one epoch = one file.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

epochtuple

Epoch and file number.

reset_metricsbool

Reset internal state of metric after eveery batch?

on_epoch_begin(epoch, logs=None)[source]

Called at the start of an epoch.

Subclasses should override for any actions to run. This function should only be called during TRAIN mode.

Args:

epoch: Integer, index of epoch. logs: Dict. Currently no data is passed to this argument for this method

but that may change in the future.

initialize_epoch()[source]

Start a new logfile and prepare the logger.

on_batch_end(batch, logs=None)[source]

A backwards compatibility alias for on_train_batch_end.

on_epoch_end(batch, logs=None)[source]
if self._stored_metrics:

# write stats of remaining batches self._write_line()

orcanet.logging.log_start_training(orga)[source]

When a training is started for the first time, this logs all the input parameters to the log.txt file.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

orcanet.logging.log_start_validation(orga)[source]

Log filenames used for validation.