class_docstr: 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.
class_docstr_tok: ["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","."]
docstr: This function receives all parameters from user config file,
  create an instance of application.
  
  :param workflow_param: a dictionary of user parameters,
      keys correspond to sections in the config file
  :param data_param: a dictionary of input image parameters,
      keys correspond to data properties to be used by image_reader
  :return:
docstr_tok: ["This","function","receives","all","parameters","from","user","config","file",",","create","an","instance","of","application",".",":","param","workflow_param",":","a","dictionary","of","user","parameters",",","keys","correspond","to","sections","in","the","config","file",":","param","data_param",":","a","dictionary","of","input","image","parameters",",","keys","correspond","to","data","properties","to","be","used","by","image_reader",":","return",":"]
code: def initialise_application(self, workflow_param, data_param=None):
      """
      This function receives all parameters from user config file,
      create an instance of application.
  
      :param workflow_param: a dictionary of user parameters,
          keys correspond to sections in the config file
      :param data_param: a dictionary of input image parameters,
          keys correspond to data properties to be used by image_reader
      :return:
      """
      try:
          system_param = workflow_param.get("SYSTEM", None)
          net_param = workflow_param.get("NETWORK", None)
          train_param = workflow_param.get("TRAINING", None)
          infer_param = workflow_param.get("INFERENCE", None)
          app_param = workflow_param.get("CUSTOM", None)
      except AttributeError:
          tf.logging.fatal("parameters should be dictionaries")
          raise
  
      assert os.path.exists(
          system_param.model_dir
      ), "Model folder not exists {}".format(system_param.model_dir)
      self.model_dir = system_param.model_dir
  
      self.is_training_action = TRAIN.startswith(
          system_param.action.lower()
      )
      # hardware-related parameters
      self.num_threads = (
          max(system_param.num_threads, 1)
          if self.is_training_action
          else 1
      )
      self.num_gpus = (
          system_param.num_gpus
          if self.is_training_action
          else min(system_param.num_gpus, 1)
      )
      set_cuda_device(system_param.cuda_devices)
  
      # set training params.
      if self.is_training_action:
          assert train_param, "training parameters not specified"
          self.initial_iter = train_param.starting_iter
          self.final_iter = max(train_param.max_iter, self.initial_iter)
          self.save_every_n = train_param.save_every_n
          self.tensorboard_every_n = train_param.tensorboard_every_n
          self.max_checkpoints = max(
              self.max_checkpoints, train_param.max_checkpoints
          )
          self.validation_every_n = train_param.validation_every_n
          self.vars_to_restore = (
              train_param.vars_to_restore
              if hasattr(train_param, "vars_to_restore")
              else ""
          )
          if self.validation_every_n > 0:
              self.validation_max_iter = max(
                  self.validation_max_iter,
                  train_param.validation_max_iter,
              )
          action_param = train_param
      else:  # set inference params.
          assert infer_param, "inference parameters not specified"
          self.initial_iter = infer_param.inference_iter
          action_param = infer_param
  
      # infer the initial iteration from model files
      if self.initial_iter < 0:
          self.initial_iter = infer_latest_model_file(
              os.path.join(self.model_dir, "models")
          )
  
      # create an application instance
      assert app_param, "application specific param. not specified"
      app_module = ApplicationFactory.create(app_param.name)
      self.app = app_module(
          net_param, action_param, system_param.action
      )
  
      # clear the cached file lists
      self.data_partitioner.reset()
      if data_param:
          do_new_partition = (
              self.is_training_action
              and (not os.path.isfile(system_param.dataset_split_file))
              and (
                  train_param.exclude_fraction_for_validation > 0
                  or train_param.exclude_fraction_for_inference > 0
              )
          )
          data_fractions = (
              (
                  train_param.exclude_fraction_for_validation,
                  train_param.exclude_fraction_for_inference,
              )
              if do_new_partition
              else None
          )
  
          self.data_partitioner.initialise(
              data_param=data_param,
              new_partition=do_new_partition,
              ratios=data_fractions,
              data_split_file=system_param.dataset_split_file,
          )
          assert (
              self.data_partitioner.has_validation
              or self.validation_every_n <= 0
          ), (
              "validation_every_n is set to {}, "
              "but train/validation splitting not available.\nPlease "
              "check dataset partition list {} "
              "(remove file to generate a new dataset partition), "
              'check "exclude_fraction_for_validation" '
              "(current config value: {}).\nAlternatively, "
              'set "validation_every_n" to -1.'.format(
                  self.validation_every_n,
                  system_param.dataset_split_file,
                  train_param.exclude_fraction_for_validation,
              )
          )
  
      # initialise readers
      self.app.initialise_dataset_loader(
          data_param, app_param, self.data_partitioner
      )
  
      # make the list of initialised event handler instances.
      self.load_event_handlers(
          system_param.event_handler or DEFAULT_EVENT_HANDLERS
      )
      self._generator = IteratorFactory.create(
          system_param.iteration_generator
          or DEFAULT_ITERATION_GENERATOR
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import time
  import tensorflow
  from niftynet.engine.application_factory import ApplicationFactory, EventHandlerFactory, IteratorFactory
  from niftynet.engine.application_iteration import IterationMessage
  from niftynet.engine.application_variables import GradientsCollector, OutputsCollector
  from niftynet.engine.signal import TRAIN, ITER_STARTED, ITER_FINISHED, GRAPH_CREATED, SESS_FINISHED, SESS_STARTED
  from niftynet.io.image_sets_partitioner import ImageSetsPartitioner
  from niftynet.io.misc_io import infer_latest_model_file
  from niftynet.utilities.user_parameters_default import DEFAULT_EVENT_HANDLERS, DEFAULT_ITERATION_GENERATOR
  from niftynet.utilities.util_common import set_cuda_device, tf_config, device_string
  from niftynet.utilities.util_common import traverse_nested
label_desc: Use image node_id 2 for calling the ApplicationDriver obj's underlying member method code with example usage: obj.initialise_application(workflow_param, data_param) without return types