code: def connect_data_and_network(
      self, outputs_collector=None, gradients_collector=None
  ):
      data_dict = self.get_sampler()[0][0].pop_batch_op()
      image = tf.cast(data_dict["image"], tf.float32)
      net_out = self.net(image, self.is_training)
  
      if self.is_training:
          with tf.name_scope("Optimiser"):
              self.learning_rate = tf.placeholder(tf.float32, shape=[])
              optimiser_class = OptimiserFactory.create(
                  name=self.action_param.optimiser
              )
              self.optimiser = optimiser_class.get_instance(
                  learning_rate=self.learning_rate
              )
          loss_func = LossFunction(
              n_class=self.segmentation_param.num_classes,
              loss_type=self.action_param.loss_type,
          )
          data_loss = loss_func(
              prediction=net_out,
              ground_truth=data_dict.get("label", None),
              weight_map=data_dict.get("weight", None),
          )
  
          loss = data_loss
          reg_losses = tf.get_collection(
              tf.GraphKeys.REGULARIZATION_LOSSES
          )
  
          if self.net_param.decay > 0.0 and reg_losses:
              reg_loss = tf.reduce_mean(
                  [tf.reduce_mean(reg_loss) for reg_loss in reg_losses]
              )
              loss = data_loss + reg_loss
          grads = self.optimiser.compute_gradients(loss)
          # collecting gradients variables
          gradients_collector.add_to_collection([grads])
          # collecting output variables
          outputs_collector.add_to_collection(
              var=data_loss,
              name="loss",
              average_over_devices=False,
              collection=CONSOLE,
          )
          outputs_collector.add_to_collection(
              var=self.learning_rate,
              name="lr",
              average_over_devices=False,
              collection=CONSOLE,
          )
          outputs_collector.add_to_collection(
              var=data_loss,
              name="loss",
              average_over_devices=True,
              summary_type="scalar",
              collection=TF_SUMMARIES,
          )
      else:
          # converting logits into final output for
          # classification probabilities or argmax classification labels
          SegmentationApplication.connect_data_and_network(
              self, outputs_collector, gradients_collector
          )
  
file_path: NiftyNet/demos/Learning_Rate_Decay/Demo_applications/decay_lr_comparison_application.py
imports: import tensorflow
  from niftynet.application.segmentation_application import SegmentationApplication
  from niftynet.engine.application_factory import OptimiserFactory
  from niftynet.engine.application_variables import CONSOLE
  from niftynet.engine.application_variables import TF_SUMMARIES
  from niftynet.layer.loss_segmentation import LossFunction
label_desc: Use image node_id 2 for calling the DecayLearningRateApplication obj's underlying member method code with example usage: obj.connect_data_and_network(outputs_collector, gradients_collector) without return types