orcanet.backend

Code for training and validating NN’s, as well as evaluating them.

Module Contents

Functions

train_model(orga, model, epoch[, batch_logger])

Train a model on one file and return the history.

validate_model(orga, model)

Validates a model on all validation files and return the history.

weighted_average(histories, f_sizes)

Average multiple histories, weighted with the file size.

h5_inference(orga, model, files_dict, output_path[, ...])

Let a model predict on all samples in a h5 file, and save it as a h5 file.

make_model_prediction(orga, model, epoch, fileno[, ...])

Let a model predict on all validation samples, and save it as a h5 file.

orcanet.backend.train_model(orga, model, epoch, batch_logger=False)[source]

Train a model on one file and return the history.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

modelkeras.Model

A compiled keras model.

epochtuple

Current epoch and the no of the file to train on.

batch_loggerbool

Use the orcanet batchlogger to log the training.

Returns
historydict

The history of the training on this file. A record of training loss values and metrics values.

orcanet.backend.validate_model(orga, model)[source]

Validates a model on all validation files and return the history.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

modelkeras.Model

A compiled keras model.

Returns
historydict

The history of the validation on all files. A record of validation loss values and metrics values.

orcanet.backend.weighted_average(histories, f_sizes)[source]

Average multiple histories, weighted with the file size.

Each history can have multiple metrics, which are averaged seperatly.

Parameters
historiesList

List of histories, one for each file. Each history is also a list: each entry is a different loss or metric.

f_sizesList

List of the file sizes, in the same order as the histories, i.e. the file of histories[0] has the length f_sizes[0].

Returns
wgtd_averageList

The weighted averaged history. Has the same length as each history in the histories List, i.e. one entry per loss or metric.

orcanet.backend.h5_inference(orga, model, files_dict, output_path, samples=None, use_def_label=True)[source]

Let a model predict on all samples in a h5 file, and save it as a h5 file.

Per default, the h5 file will contain a datagroup y_values straight from the given files, as well as two datagroups per output layer of the network, which have the labels and the predicted values in them as numpy arrays, respectively.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

modelkeras.Model

Trained Keras model of a neural network.

files_dictdict

Dict mapping model input names to h5 file paths.

output_pathstr

Name of the output h5 file containing the predictions.

samplesint, optional

Dont use all events in the file, but instead only the given number.

use_def_labelbool

If True and no label modifier is given by user, use the default label modifier instead of none.

orcanet.backend.make_model_prediction(orga, model, epoch, fileno, samples=None)[source]

Let a model predict on all validation samples, and save it as a h5 file.

Per default, the h5 file will contain a datagroup y_values straight from the given files, as well as two datagroups per output layer of the network, which have the labels and the predicted values in them as numpy arrays, respectively.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

modelkeras.Model

A compiled keras model.

epochint

Epoch of the last model training step in the epoch, file_no tuple.

filenoint

File number of the last model training step in the epoch, file_no tuple.

samplesint or None

Number of events that should be predicted. If samples=None, the whole file will be used.