class_docstr: This class handles iteration events to update the model with gradient op
  (by setting iteration message with a 'gradients' op at the beginning of
  each iteration).
class_docstr_tok: ["This","class","handles","iteration","events","to","update","the","model","with","gradient","op","(","by","setting","iteration","message","with","a","'gradients","'","op","at","the","beginning","of","each","iteration",")","."]
docstr: Event handler to add gradients to iteration message ops_to_run.
  
  See also
  ``niftynet.application.base_application.set_network_gradient_op``
  
  :param sender: a niftynet.application instance
  :param msg: an iteration message instance
  :return:
docstr_tok: ["Event","handler","to","add","gradients","to","iteration","message","ops_to_run",".","See","also","``","niftynet.application.base_application.set_network_gradient_op","``",":","param","sender",":","a","niftynet.application","instance",":","param","msg",":","an","iteration","message","instance",":","return",":"]
code: def add_gradients(self, sender, **msg):
      """
      Event handler to add gradients to iteration message ops_to_run.
  
      See also
      ``niftynet.application.base_application.set_network_gradient_op``
  
      :param sender: a niftynet.application instance
      :param msg: an iteration message instance
      :return:
      """
      if msg["iter_msg"].is_training:
          msg["iter_msg"].ops_to_run["gradients"] = sender.gradient_op
  
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 3 for calling the ApplyGradients obj's underlying member method code with example usage: obj.add_gradients(sender) without return types