class_docstr: Setup CNTK ops with given parameters
class_docstr_tok: ["Setup","CNTK","ops","with","given","parameters"]
docstr:  Setup batch normalization op with given parameters
  
  Args:
      cntk_layer (:class:`~cntk.contrib.crosstalkcaffe.unimodel.cntkmodel.CntkLayersDefinition`):
          the layer definition of batch normalization op
      inputs (list): a list contains all :class:`~cntk.ops.functions.Function` or
          :class:`~cntk.input`
  
  Return:
      :func:`~cntk.ops.functions.Function`: instaced cntk batch normalization op
docstr_tok: ["Setup","batch","normalization","op","with","given","parameters","Args",":","cntk_layer","(",":","class",":","`","~cntk.contrib.crosstalkcaffe.unimodel.cntkmodel.CntkLayersDefinition","`",")",":","the","layer","definition","of","batch","normalization","op","inputs","(","list",")",":","a","list","contains","all",":","class",":","`","~cntk.ops.functions.Function","`","or",":","class",":","`","~cntk.input","`","Return",":",":","func",":","`","~cntk.ops.functions.Function","`",":","instaced","cntk","batch","normalization","op"]
code: def batch_norm(cntk_layer, inputs):
      """
       Setup batch normalization op with given parameters
  
      Args:
          cntk_layer (:class:`~cntk.contrib.crosstalkcaffe.unimodel.cntkmodel.CntkLayersDefinition`):
              the layer definition of batch normalization op
          inputs (list): a list contains all :class:`~cntk.ops.functions.Function` or
              :class:`~cntk.input`
  
      Return:
          :func:`~cntk.ops.functions.Function`: instaced cntk batch normalization op
      """
      sanitize_input = internal.sanitize_input(inputs[0])
      parameter_tensor = (sanitize_input.shape[0],)
      scale_init = 1
      bias_init = 0
      mean_init = 1
      var_init = 0
      if cntk_layer.parameter_tensor:
          if len(cntk_layer.parameter_tensor) < 3:
              raise AssertionError(
                  "At least three tensors (saved_mean, saved_variance and scale) are needed"
              )
          mean_tensor = cntk_layer.parameter_tensor[0]
          variance_tensor = cntk_layer.parameter_tensor[1]
          global_scale = cntk_layer.parameter_tensor[2].data[0]
          moving_average_factor = (
              1 / global_scale if global_scale != 0 else 0
          )
          mean_init = (
              np.asarray(mean_tensor.data, dtype=np.float32)
              * moving_average_factor
          )
          var_init = (
              np.asarray(variance_tensor.data, dtype=np.float32)
              * moving_average_factor
          )
          if len(cntk_layer.parameter_tensor) == 5:
              scale_tensor = cntk_layer.parameter_tensor[3]
              bias_tensor = cntk_layer.parameter_tensor[4]
              scale_init = np.asarray(
                  scale_tensor.data, dtype=np.float32
              )
              bias_init = np.asarray(bias_tensor.data, dtype=np.float32)
  
      scale_parameters = ops.parameter(
          parameter_tensor,
          init=scale_init,
          name=".".join((cntk_layer.op_name, "scale")),
      )
      bias_parameters = ops.parameter(
          parameter_tensor,
          init=bias_init,
          name=".".join((cntk_layer.op_name, "bias")),
      )
      mean_parameters = ops.parameter(
          parameter_tensor,
          init=mean_init,
          name=".".join((cntk_layer.op_name, "mean")),
      )
      var_parameters = ops.parameter(
          parameter_tensor,
          init=var_init,
          name=".".join((cntk_layer.op_name, "var")),
      )
      epsilon = cntk_layer.parameters.epsilon
  
      return ops.batch_normalization(
          sanitize_input,
          scale_parameters,
          bias_parameters,
          mean_parameters,
          var_parameters,
          True,
          use_cudnn_engine=False,
          epsilon=epsilon,
          running_count=ops.constant(0),
          name=cntk_layer.op_name,
      )
  
imports: from operator import mul
  from functools import reduce
  import numpy
  import cntk
  import cntk.io.transforms
  from cntk import ops, io, learners, internal
  from cntk import Trainer
  from cntk.layers.blocks import BlockFunction
label_desc: Use image node_id 2 for calling the ApiSetup obj's underlying member method code with example usage: obj.batch_norm(cntk_layer, inputs) and returns: ops