code: def align_arcface(image, landmarks):
      """
      Aligns 'image' with its corresponding 'landmarks' to a predefined template
      with similarity transformation. This is the tensorflow implementation of
      the default alignment procedure of ArcFace
      Args:
          image: a 4D float32 numpy array with shape [batch_size, image_height,
          image_width, 3].
          landmarks: 68 iBug landmark points of 'image'. [batch_size, 68, 2]
  
      Returns:
          4-D float32 numpy array with shape [batch_size, 112, 112, 3]. Contains
          aligned version of 'image'
  
      """
  
      image_size = (112, 112)
      dst = np.array(
          [
              [30.2946, 51.6963],
              [65.5318, 51.5014],
              [48.0252, 71.7366],
              [33.5493, 92.3655],
              [62.7299, 92.2041],
          ],
          dtype=np.float32,
      )
      if image_size[1] == 112:
          dst[:, 0] += 8.0
      # dst = dst[:, ::-1]
      landmark5 = tf.stack(
          [
              (landmarks[:, 36] + landmarks[:, 39]) / 2,
              (landmarks[:, 42] + landmarks[:, 45]) / 2,
              landmarks[:, 30],
              landmarks[:, 48],
              landmarks[:, 54],
          ],
          1,
      )
  
      def py_similarity_transform(src, dst):
          tform = trans.SimilarityTransform()
          Ms = np.zeros([0, 3, 3], dtype=np.float32)
          for s in src:
              tform.estimate(s, dst)
              Ms = np.concatenate([Ms, [tform.params]], 0)
          return Ms
  
      M = tf.py_func(
          py_similarity_transform,
          [landmark5, tf.constant(dst, "float32")],
          tf.double,
          stateful=False,
      )
      M.set_shape([image.get_shape().as_list()[0], 3, 3])
  
      aligned = tf.contrib.image.transform(
          image,
          tf.cast(
              tf.contrib.image.matrices_to_flat_transforms(
                  tf.map_fn(tf.linalg.inv, M)
              ),
              "float32",
          ),
          interpolation="BILINEAR",
      )
  
      return aligned[:, 0 : image_size[0], 0 : image_size[1], :]
  
file_path: insightface/reconstruction/ostec/core/arcface_handler.py
imports: import tensorflow
  import numpy
  from external import arcface50
  from skimage import transform
label_desc: Use image node_id 1 for calling a global function with example usage: align_arcface(image, landmarks) and returns: aligned, Ms