niftynet.engine.application_driver module

This module defines a general procedure for running applications.

Example usage::
app_driver = ApplicationDriver() app_driver.initialise_application(system_param, input_data_param) app_driver.run_application()

system_param and input_data_param should be generated using:

class ApplicationDriver[source]

Bases: object

This class initialises an application by building a TF graph, and maintaining a session. It controls the starting/stopping of an application. Applications should be implemented by inheriting niftynet.application.base_application to be compatible with this driver.

initialise_application(workflow_param, data_param=None)[source]

This function receives all parameters from user config file, create an instance of application.

  • workflow_param – a dictionary of user parameters, keys correspond to sections in the config file
  • data_param – a dictionary of input image parameters, keys correspond to data properties to be used by image_reader

run(application, graph=None)[source]

Initialise a TF graph, connect data sampler and network within the graph context, run training loops or inference loops.

  • application – a niftynet application
  • graph – default base graph to run the application

static create_graph(application, num_gpus=1, num_threads=1, is_training_action=False)[source]

Create a TF graph based on properties and engine parameters.


Import event handler modules and create a list of handler instances. The event handler instances will be stored with this engine.

Parameters:names – strings of event handlers
static loop(application, iteration_messages=(), loop_status=None)[source]

Running loop_step with IterationMessage instances generated by iteration_generator.

This loop stops when any of the condition satisfied:
  1. no more element from the iteration_generator;
  2. application.interpret_output returns False;
  3. any exception raised.

Broadcasting SESS_* signals at the beginning and end of this method.

This function should be used in a context of tf.Session or session.as_default().

  • application – a niftynet.application instance, application will provides tensors to be fetched by
  • iteration_messages – a generator of engine.IterationMessage instances
  • loop_status – optional dictionary used to capture the loop status, useful when the loop exited in an unexpected manner.

static loop_step(application, iteration_message)[source]

Calling with parameters encapsulated in iteration message as an iteration. Broadcasting ITER_* events before and afterward.

  • application
  • iteration_message – an engine.IterationMessage instances