docstr: Compute loss from `prediction` and `ground truth`,
  
  if `prediction `is list of tensors, each element of the list
  will be compared against `ground_truth`.
  
  :param prediction: input will be reshaped into (N, num_classes)
  :param ground_truth: input will be reshaped into (N,)
  :param var_scope:
  :return:
docstr_tok: ["Compute","loss","from","`","prediction","`","and","`","ground","truth","`",",","if","`","prediction","`","is","list","of","tensors",",","each","element","of","the","list","will","be","compared","against","`","ground_truth","`",".",":","param","prediction",":","input","will","be","reshaped","into","(","N",",","num_classes",")",":","param","ground_truth",":","input","will","be","reshaped","into","(","N",",",")",":","param","var_scope",":",":","return",":"]
code: def layer_op(
      self,
      prediction,
      ground_truth=None,
      var_scope=None,
  ):
      """
      Compute loss from `prediction` and `ground truth`,
  
      if `prediction `is list of tensors, each element of the list
      will be compared against `ground_truth`.
  
      :param prediction: input will be reshaped into (N, num_classes)
      :param ground_truth: input will be reshaped into (N,)
      :param var_scope:
      :return:
      """
  
      with tf.device("/cpu:0"):
          if ground_truth is not None:
              ground_truth = tf.reshape(ground_truth, [-1])
  
          if not isinstance(prediction, (list, tuple)):
              prediction = [prediction]
          # prediction should be a list for holistic networks
          if self._num_classes > 0:
              # reshape the prediction to [n_voxels , num_classes]
              prediction = [
                  tf.reshape(pred, [-1, self._num_classes])
                  for pred in prediction
              ]
  
          data_loss = []
          for pred in prediction:
              if self._loss_func_params:
                  data_loss.append(
                      self._data_loss_func(
                          pred, ground_truth, **self._loss_func_params
                      )
                  )
              else:
                  data_loss.append(
                      self._data_loss_func(pred, ground_truth)
                  )
          return tf.reduce_mean(data_loss)
  
file_path: NiftyNet/niftynet/layer/loss_classification.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  from niftynet.engine.application_factory import LossClassificationFactory
  from niftynet.layer.base_layer import Layer
label_desc: Use image node_id 3 for calling the LossFunction obj's underlying member method code with example usage: obj.layer_op(prediction, ground_truth, var_scope) and returns: tf