code: def FusedBatchNormV3(context, node):
      # helper function that add the batch norm layer
      def _add_batch_norm(
          x, mean, variance, scale, offset, epsilon, name
      ):
          if mean.shape[0] != 0 and variance.shape[0] != 0:
              # In this case, we can use the mb.batch_norm directly
              x = mb.batch_norm(
                  x=x,
                  mean=mean,
                  variance=variance,
                  gamma=scale,
                  beta=offset,
                  epsilon=epsilon,
                  name=name,
              )
          else:
              # In this case, we need to manually compute the batch_norm
              axes = [axis for axis in range(x.rank) if axis != 1]
              mean = mb.reduce_mean(x=x, axes=axes, keep_dims=True)
              num = mb.sub(x=x, y=mean)
              square = mb.mul(x=num, y=num)
              variance = mb.reduce_mean(
                  x=square, axes=axes, keep_dims=True
              )
              variance_add_epsilon = mb.add(x=variance, y=epsilon)
              sqrt = mb.sqrt(x=variance_add_epsilon)
              x = mb.real_div(x=num, y=sqrt)
  
              shape = [1] * x.rank
              shape[1] = (
                  -1 if any_symbolic(scale.shape) else scale.shape[0]
              )
              scale_reshape = mb.reshape(x=scale, shape=shape)
              offset_reshape = mb.reshape(x=offset, shape=shape)
  
              x = mb.mul(x=x, y=scale_reshape)
              x = mb.add(x=x, y=offset_reshape, name=name)
  
          return x
  
      # Get attributes
      data_format = node.attr.get("data_format", "NHWC")
      epsilon = node.attr.get("epsilon", None)
  
      # Get inputs
      x = context[node.inputs[0]]
      scale = context[node.inputs[1]]
      offset = context[node.inputs[2]]
      mean = context[node.inputs[3]]
      variance = context[node.inputs[4]]
      input_dtype = x.dtype
  
      batch_norm_name = (
          node.name + "_nchw" if data_format == "NHWC" else node.name
      )
  
      if data_format == "NHWC":
          x = _transpose_NHWC_to_NCHW(x)
      elif data_format == "NDHWC":
          x = _transpose_NDHWC_to_NCDHW(x)
  
      x = mb.cast(x=x, dtype=builtin_to_string(mean.dtype))
  
      x = _add_batch_norm(
          x, mean, variance, scale, offset, epsilon, batch_norm_name
      )
  
      if data_format == "NHWC":
          x = _transpose_NCHW_to_NHWC(x, node.name + "_to_NHWC")
      elif data_format == "NDHWC":
          x = _transpose_NCDHW_to_NDHWC(x, node.name + "_to_NDHWC")
  
      x = mb.cast(
          x=x, dtype=builtin_to_string(input_dtype), name=node.name
      )
  
      # Inference only batch norm does not have meaningful outputs for
      # batch_mean, batch_variance etc.
      context.add(node.name, x)
  
file_path: coremltools/coremltools/converters/mil/frontend/tensorflow2/ops.py
imports: import numpy
  from coremltools.converters.mil.frontend.tensorflow.convert_utils import convert_graph
  from coremltools.converters.mil.frontend.tensorflow.ops import _transpose_NCDHW_to_NDHWC, _transpose_NCHW_to_NHWC, _transpose_NDHWC_to_NCDHW, _transpose_NHWC_to_NCHW
  from coremltools.converters.mil.frontend.tensorflow.tf_op_registry import register_tf_op
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil.types import builtin_to_string
  from coremltools.converters.mil.mil.types.symbolic import any_symbolic
label_desc: Use image node_id 1 for calling a global function with example usage: FusedBatchNormV3(context, node) and returns: x