code: def _apply_multiopt_gradients(optimiser, gradients):
      """
      Apply gradients by using the corresponding optimiser.
      This function sets ``self.gradient_op``.
  
      :param optimiser: single optimiser or dict of optimisers
          to be used to process the passed gradients
      :param gradients: list or dict (having a reference to the optimiser used)
          of processed gradients from the gradient_collector
      :return:
      """
  
      if isinstance(gradients, dict):
          ret = list()
          for key in sorted(gradients):
              optimiser_k = (
                  optimiser.get(key)
                  if isinstance(optimiser, dict)
                  else optimiser
              )
              if not optimiser_k:
                  tf.logging.fatal("No optimizer found for %s", key)
                  raise ValueError
              ret.append(_apply_gradients(optimiser_k, gradients[key]))
          return ret
      return _apply_gradients(optimiser, gradients)
  
file_path: NiftyNet/niftynet/engine/handler_gradient.py
imports: import tensorflow
  from niftynet.engine.signal import ITER_STARTED, GRAPH_CREATED
  from niftynet.layer.bn import BN_COLLECTION
  from niftynet.utilities import util_common
label_desc: Use image node_id 1 for calling a global function with example usage: _apply_multiopt_gradients(optimiser, gradients) and returns: _apply_gradients, ret