code: def rot_to_quat(R):
      batch_size, _, _ = R.shape
      q = torch.ones((batch_size, 4)).cuda()
  
      R00 = R[:, 0, 0]
      R01 = R[:, 0, 1]
      R02 = R[:, 0, 2]
      R10 = R[:, 1, 0]
      R11 = R[:, 1, 1]
      R12 = R[:, 1, 2]
      R20 = R[:, 2, 0]
      R21 = R[:, 2, 1]
      R22 = R[:, 2, 2]
  
      q[:, 0] = torch.sqrt(1.0 + R00 + R11 + R22) / 2
      q[:, 1] = (R21 - R12) / (4 * q[:, 0])
      q[:, 2] = (R02 - R20) / (4 * q[:, 0])
      q[:, 3] = (R10 - R01) / (4 * q[:, 0])
      return q
  
file_path: insightface/reconstruction/PBIDR/code/utils/rend_util.py
imports: import numpy
  import imageio
  import skimage
  import cv2
  import torch
  from torch.nn import functional
label_desc: Use image node_id 9 for calling a global function with example usage: rot_to_quat(R) and returns: q