code: def _apply_gradients(optimiser, gradients):
      """
      Apply gradients op by ``optimiser.apply_gradients``.
  
      :param optimiser: single optimiser processing the passed gradients
      :param gradients: processed gradients from the gradient_collector
      :return:
      """
  
      grad_list_depth = util_common.list_depth_count(gradients)
      if grad_list_depth == 3:
          # nested depth 3 means: gradients list is nested in terms of:
          # list of networks -> list of network variables
          return [optimiser.apply_gradients(grad) for grad in gradients]
      elif grad_list_depth == 2:
          # nested depth 2 means:
          # gradients list is a list of variables
          return optimiser.apply_gradients(gradients)
      raise NotImplementedError(
          "This app supports updating a network, or a list of networks."
      )
  
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 2 for calling a global function with example usage: _apply_gradients(optimiser, gradients) and returns: unknown, optimiser