code: def rotate_image_tensor(image, angle):
      s = tf.shape(image)
      image_center = tf.to_float(s[:2]) / 2.0
  
      # Coordinates of new image
      xs, ys = tf.meshgrid(
          tf.range(0.0, tf.to_float(s[1])),
          tf.range(0.0, tf.to_float(s[0])),
      )
      coords_new = tf.reshape(tf.stack([ys, xs], 2), [-1, 2])
  
      # center coordinates since rotation center is supposed to be in the image center
      coords_new_centered = tf.to_float(coords_new) - image_center
  
      # Perform backward transformation of the image coordinates
      rot_mat_inv = tf.stack(
          [tf.cos(angle), tf.sin(angle), -tf.sin(angle), tf.cos(angle)]
      )
      rot_mat_inv = tf.reshape(rot_mat_inv, shape=[2, 2])
      coord_old_centered = tf.matmul(
          rot_mat_inv, tf.transpose(coords_new_centered)
      )
      coord_old = tf.to_int32(
          tf.round(tf.transpose(coord_old_centered) + image_center)
      )
  
      # Find nearest neighbor in old image
      coord_old_y, coord_old_x = tf.unstack(coord_old, axis=1)
  
      # Clip values to stay inside image coordinates
      outside_y = tf.logical_or(
          tf.greater(coord_old_y, s[0] - 1), tf.less(coord_old_y, 0)
      )
      outside_x = tf.logical_or(
          tf.greater(coord_old_x, s[1] - 1), tf.less(coord_old_x, 0)
      )
      outside_ind = tf.logical_or(outside_y, outside_x)
  
      inside_mask = tf.logical_not(outside_ind)
      inside_mask = tf.tile(
          tf.reshape(inside_mask, s[:2])[..., None],
          tf.stack([1, 1, s[2]]),
      )
  
      coord_old_y = tf.clip_by_value(coord_old_y, 0, s[0] - 1)
      coord_old_x = tf.clip_by_value(coord_old_x, 0, s[1] - 1)
      coord_flat = coord_old_y * s[1] + coord_old_x
  
      im_flat = tf.reshape(image, tf.stack([-1, s[2]]))
      rot_image = tf.gather(im_flat, coord_flat)
      rot_image = tf.reshape(rot_image, s)
  
      return tf.where(inside_mask, rot_image, tf.zeros_like(rot_image))
  
file_path: insightface/reconstruction/ostec/external/landmark_detector/data_provider.py
imports: import tensorflow
  import numpy
  from menpo.transform import Translation
  from external.landmark_detector.flags import FLAGS
label_desc: Use image node_id 3 for calling a global function with example usage: rotate_image_tensor(image, angle) and returns: tf