code: def normalize(tensor, norm_type, epsilon=1e-6):
      """Normalizes the values in `tensor` with respect to a specified vector norm.
  
      This op assumes that the first axis of `tensor` is the batch dimension, and
      calculates the norm over all other axes. For example, if `tensor` is
      `tf.constant(1.0, shape=[2, 3, 4])`, its L2 norm (calculated along all the
      dimensions other than the first dimension) will be `[[sqrt(12)], [sqrt(12)]]`.
      Hence, this tensor will be normalized by dividing by
      `[[sqrt(12)], [sqrt(12)]]`.
  
      Note that `tf.norm` is not used here since it only allows the norm to be
      calculated over one axis, not multiple axes.
  
      Args:
        tensor: a tensor to be normalized. Can have any shape with the first axis
          being the batch dimension that will not be normalized across.
        norm_type: one of `nsl.configs.NormType`, the type of vector norm.
        epsilon: a lower bound value for the norm to avoid division by 0.
  
      Returns:
        A normalized tensor with the same shape and type as `tensor`.
      """
      if isinstance(
          norm_type, str
      ):  # Allows string to be converted into NormType.
          norm_type = configs.NormType(norm_type)
  
      target_axes = list(range(1, len(tensor.get_shape())))
      if norm_type == configs.NormType.INFINITY:
          norm = tf.reduce_max(
              input_tensor=tf.abs(tensor),
              axis=target_axes,
              keepdims=True,
          )
          norm = tf.maximum(norm, epsilon)
          normalized_tensor = tensor / norm
      elif norm_type == configs.NormType.L1:
          norm = tf.reduce_sum(
              input_tensor=tf.abs(tensor),
              axis=target_axes,
              keepdims=True,
          )
          norm = tf.maximum(norm, epsilon)
          normalized_tensor = tensor / norm
      elif norm_type == configs.NormType.L2:
          normalized_tensor = tf.nn.l2_normalize(
              tensor, axis=target_axes, epsilon=epsilon**2
          )
      else:
          raise NotImplementedError(
              'Unrecognized or unimplemented "norm_type": %s'
              % norm_type
          )
      return normalized_tensor
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import neural_structured_learning.configs
  import six
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: normalize(tensor, norm_type, epsilon) and returns: normalized_tensor