barrage package

Submodules

barrage.api module

class barrage.api.RecordLoader(mode, **params)[source]

Bases: abc.ABC

Class for loading records into DataRecord.

Parameters

mode (RecordMode) – RecordMode, load mode.

abstract load(record)[source]

Method for loading a record into DataRecord.

Parameters

record (Dict[str, Any]) – Record, record.

Return type

Tuple[Dict[str, Union[ndarray, float]], …]

Returns

DataRecord, data record.

class barrage.api.RecordMode(value)[source]

Bases: enum.Enum

An enumeration.

SCORE = 2
TRAIN = 0
VALIDATION = 1
class barrage.api.RecordTransformer(mode, loader, **params)[source]

Bases: abc.ABC

Class that computes a transform on training data records & applys transform to validation and scoring data records (network input), ability to pass computed network params to the network builder, and ability to apply inverse transforms on record scores (network output).

Parameters
abstract fit(records)[source]

Fit transform to records.

Parameters

records (List[Dict[str, Any]]) – Records, records.

abstract load(path)[source]

Load transformer.

Parameters

path (str) – str.

property network_params

Special params passed to the network builder.

Return type

dict

abstract postprocess(score)[source]

Postprocess score to undo transform.

Parameters

score (Dict[str, ndarray]) – RecordScore, record output from net.

Return type

Dict[str, ndarray]

Returns

RecordScore, postprocessed record output from net.

abstract save(path)[source]

Save transformer.

Parameters

path (str) – str.

abstract transform(data_record)[source]

Apply transform to a data record.

Parameters

data_record (Tuple[Dict[str, Union[ndarray, float]], …]) – DataRecord, data record.

Return type

Tuple[Dict[str, Union[ndarray, float]], …]

Returns

DataRecord, data record.

barrage.config module

barrage.config.prepare_config(cfg)[source]

Prepare config for use - apply defaults, validate schema.

Parameters

cfg (dict) – dict, config.

Return type

dict

Returns

dict, validated config with defaults.

barrage.console module

barrage.defaults module

barrage.engine module

class barrage.engine.BarrageModel(artifact_dir)[source]

Bases: object

Class for training the network and scoring records with best performing network.

Parameters

artifact_dir – str, path to artifact directory.

property artifact_dir
load()[source]

Load the best performing checkpoint.

predict(records_score)[source]

Score records.

Parameters

records_score (Union[List[Dict[str, Any]], DataFrame]) – InputRecords, scoring records.

Return type

List[Dict[str, ndarray]]

Returns

BatchRecordScores, scored data records.

train(cfg, records_train, records_validation)[source]

Train the network.

Parameters
  • cfg (dict) – dict, config.

  • records_train (Union[List[Dict[str, Any]], DataFrame]) – InputRecords, training records.

  • records_validation (Union[List[Dict[str, Any]], DataFrame]) – InputRecords, validation records.

Return type

Model

Returns

tf.keras.Model, trained network.

barrage.log module

barrage.model module

barrage.model.build_network(cfg_model, transform_params)[source]

Build the network.

Parameters
  • cfg_model (dict) – dict, model subsection of config.

  • transform_params (dict) – dict, params from transformer.

Return type

Model

Returns

tf.keras.Model, network.

Raises

TypeError, network not a tf.keras.Model.

barrage.model.build_objective(cfg_model)[source]

Build objective (loss, loss_weights, metrics, and sample_weight_mode) for each model output.

Parameters

cfg_model (dict) – dict, model subsection of config.

Return type

dict

Returns

dict, objective

barrage.model.check_output_names(cfg_model, net)[source]

Check the net outputs in the config match the actual net.

Parameters
  • cfg_model (dict) – dict, model subsection of config.

  • net (Model) – tf.keras.Model, net.

Raises

ValueError, mismatch between config and net.

barrage.model.sequential_from_config(layers, **kwargs)[source]

Build a sequential model from a list of layer specifications. Supports references to network_params computed inside Transformers by specifying {{variable name}}.

Parameters

layers (List[dict]) – list[dict], layer imports.

Return type

Model

Returns

tf.keras.Model, network.

barrage.services module

barrage.services.create_all_services(artifact_dir, cfg_services)[source]

Create all services (callbacks).

Parameters
  • artifact_dir (str) – str, path to artifact directory.

  • cfg_services (dict) – dict, services subsection of config.

Return type

List[Callback]

Returns

list[Callback], all services.

barrage.services.get_best_checkpoint_filepath(artifact_dir)[source]

Get the filepath for the best checkpoint.

Parameters

artifact_dir (str) – str, path to artifact directory.

Return type

str

Returns

str, filepath for best checkpoint directory.

barrage.services.get_resume_checkpoints_filepath(artifact_dir)[source]

Get the filepath for the resume checkpoints.

Parameters

artifact_dir (str) – str, path to artifact directory.

Return type

str

Returns

str, filepath for resume checkpoints.

barrage.services.make_artifact_dir(artifact_dir)[source]

Make the artifact directory and all required subdirectories.

Parameters

artifact_dir (str) – str, path to artifact directory.

Raises

OSError, artifact_dir already exists.

barrage.solver module

barrage.solver.build_optimizer(cfg_solver)[source]

Build the optimizer.

Parameters

cfg_solver (dict) – dict, solver subsection of config.

Return type

OptimizerV2

Returns

optimizer_v2.OptimizerV2, tf.keras v2 optimizer.

Raises
  • TypeError, optimizer not an OptimizerV2.

  • TypeError, learning rate is not a float or LearningRateSchedule.

barrage.solver.create_learning_rate_reducer(cfg_solver)[source]

Create a ReduceLROnPlateau callback.

Parameters

cfg_solver (dict) – dict, solver subsection of config.

Return type

ReduceLROnPlateau

Returns

ReduceLROnPlateau, ReduceLROnPlateau callback.

Module contents