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:
niftynet.utilities.user_parameters_parser.run()
-
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.
Parameters: - 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
Returns:
-
run
(application, graph=None)[source]¶ Initialise a TF graph, connect data sampler and network within the graph context, run training loops or inference loops.
Parameters: - application – a niftynet application
- graph – default base graph to run the application
Returns:
-
static
create_graph
(application, num_gpus=1, num_threads=1, is_training_action=False)[source]¶ Create a TF graph based on self.app properties and engine parameters.
Returns:
-
load_event_handlers
(names)[source]¶ 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 Returns:
-
static
loop
(application, iteration_messages=(), loop_status=None)[source]¶ Running
loop_step
withIterationMessage
instances generated byiteration_generator
.- This loop stops when any of the condition satisfied:
- no more element from the
iteration_generator
; application.interpret_output
returns False;- any exception raised.
- no more element from the
Broadcasting SESS_* signals at the beginning and end of this method.
This function should be used in a context of
tf.Session
orsession.as_default()
.Parameters: - application – a niftynet.application instance, application
will provides
tensors
to be fetched bytf.session.run()
. - 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.
Returns:
-