orcanet.model_builder

Scripts for making specific models.

Module Contents

Classes

ModelBuilder

Build and compile a keras model from a toml file, using OrcaNet building blocks.

Functions

get_adam([beta_1, beta_2, epsilon, decay])

get_sgd([momentum, decay, nesterov])

class orcanet.model_builder.ModelBuilder(model_file, **custom_blocks)[source]

Build and compile a keras model from a toml file, using OrcaNet building blocks.

The input of the model can match the dimensions of the input data given to the Organizer taking into account the sample modifier.

Attributes
configslist

List with keywords for building each layer block in the model.

defaultsdict

Default values for the layer blocks in the model.

optimizerstr or Optimizer

Optimizer for training the model. Can be a string like “adam” (or “keras:adam” for the default keras variant), or an object derived from ks.optimizers.Optimizer.

compile_optdict

Keys: Names of the output layers of the model. Values: Loss function, optionally weight and optionally metric of each output layer. Format: { layer_name : { loss_function:, weight:, metrics: } } The loss_function is a string or a function, the weight is a float and metrics is a list of functions/strings.

optimizer_argsdict, optional

Kwargs for the optimizer. Not used when an optimizer object is given.

input_optsdict

Specify options for the input of the model.

Methods

build

Build the network using an instance of Organizer.

build_with_input

Build the network without an Organizer, just using given input shapes.

compile

Compile a model with the optimizer settings given in the model_file.

build(orga, log_comp_opts=False, verbose=False)[source]

Build the network using an instance of Organizer.

Input layers will be adapted to the input files in the organizer. Can also add the matching modifiers and custom objects to the orga.

Parameters
orgaorcanet.core.Organizer

Contains all the configurable options in the OrcaNet scripts.

log_comp_optsbool

If the info used for the compilation of the model should be logged to the log.txt.

verbosebool

Print info about the building process?

Returns
modelkeras model

The network.

build_with_input(input_shapes, compile_model=True, custom_objects=None, verbose=False)[source]

Build the network with given input shapes.

Parameters
input_shapesdict

Keys: Name of the inputs of the model. Values: Their shape without the batchsize.

compile_modelbool

Compile the model?

custom_objectsdict, optional

Custom objects to use during compiling.

verbosebool

Print info about the building process?

Returns
modelks.Model

The network.

compile_model(model, custom_objects=None)[source]

Compile a model with the optimizer settings given as the attributes.

Parameters
modelks.model

A keras model.

custom_objectsdict or None

Maps names (strings) to custom loss functions.

Returns
modelkeras model

The compiled (or recompiled) keras model.

log_model_properties(orga)[source]

Writes the compile_opt config to the full log file.

orcanet.model_builder.get_adam(beta_1=0.9, beta_2=0.999, epsilon=0.1, decay=0.0, **kwargs)[source]
orcanet.model_builder.get_sgd(momentum=0.9, decay=0, nesterov=True, **kwargs)[source]