code: def evaluate(val_loader, pose_model, config, is_train=False):
      # is_train flag for generating the 3d predictions for training set
      num_frames = config.DATA.NUM_FRAMES
      use_same_norm_3d = config.DATA.USE_SAME_NORM_3D
      prefix = "mpi" if config.DATA.DATASET_NAME == "mpi" else "h36m"
      pose_model.eval()
      valid_cnt = 0
      test3d_loss_total_p1, test3d_loss_total_p2 = 0.0, 0.0
      pred_3ds, gt_3ds, all_scales, all_scale_mids, Rs = (
          [],
          [],
          [],
          [],
          [],
      )
      if is_train:
          factor = 0.6451607 if prefix == "h36m" else 0.729043041
      else:
          factor = 0.680019 if prefix == "h36m" else 0.7577316
      if not use_same_norm_3d:
          factor_filename = (
              f"../data/{prefix}_test_factor_3d.pkl"
              if not is_train
              else f"../data/{prefix}_train_factor_3d.pkl"
          )
          with open(factor_filename, "rb") as f:
              factor = torch.from_numpy(pkl.load(f)).cuda()
      # print('eval with 15 joints')
      # joint_indices = list(range(14)) + [16]
      with torch.no_grad():
          t = tqdm(val_loader, desc=f"Evaluating...")
          for kp2ds_, kp3ds, _, _, _, _ in t:
              if valid_cnt == 0:
                  bs = kp2ds_.size(0)
              kp2ds = kp2ds_.cuda()
              kp3ds = kp3ds.cuda()
              pred_3d, scales, scale_mids = pose_model(
                  kp2ds, is_train=False, rot=None
              )
              root3d, root3d_pred = (
                  kp3ds[:, 13:14].clone(),
                  pred_3d[:, 13:14].clone(),
              )
              kp3ds, pred_3d = kp3ds - root3d, pred_3d - root3d_pred
              # rescale back to original scale from 1 unit
              if not use_same_norm_3d:
                  pred_3d = (
                      pred_3d
                      * factor[
                          int(bs * valid_cnt) : int(
                              bs * (valid_cnt + 1)
                          )
                      ]
                  )
              else:
                  pred_3d = pred_3d * factor
              pred_numpy, gt_numpy = (
                  pred_3d.cpu().numpy(),
                  kp3ds.cpu().numpy(),
              )
              scales = scales.cpu().numpy()
              scale_mids = scale_mids.cpu().numpy()
              pred_3ds.append(pred_numpy)
              gt_3ds.append(gt_numpy)
              all_scales.append(scales)
              all_scale_mids.append(scale_mids)
              # calculate the p1 and p2 mpjpe
              err_p1 = (
                  np.sqrt(
                      ((pred_numpy - gt_numpy) ** 2).sum(axis=-1)
                  ).mean()
                  * 1000.0
              )
              # err_p1 = p_mpjpe(pred_numpy, gt_numpy, rot=False) * 1000.0
              # err_p2 = p_mpjpe(pred_numpy[:, joint_indices], gt_numpy[:, joint_indices], rot=True, trans=True) * 1000.0
              err_p2 = (
                  p_mpjpe(pred_numpy, gt_numpy, rot=True, trans=True)
                  * 1000.0
              )
              # err_p2, R = p_mpjpe(pred_numpy, gt_numpy, rot=True, trans=False, scale=False)
              # err_p2 *= 1000.0
              # Rs.append(R)
              test3d_loss_total_p1 += err_p1
              test3d_loss_total_p2 += err_p2
              valid_cnt += 1
      # Rs = np.concatenate(Rs, axis=0)
      # with open("../data/rotations_{}.pkl".format("train" if is_train else "valid"), "wb") as f:
      #     pkl.dump(Rs, f)
      all_out_data = {
          "p1_mpjpe": test3d_loss_total_p1 / valid_cnt,
          "p2_mpjpe": test3d_loss_total_p2 / valid_cnt,
          "joint_3d_gt": np.concatenate(gt_3ds, axis=0),
          "joint_3d_pre": np.concatenate(pred_3ds, axis=0),
          "scales": np.concatenate(all_scales, axis=0),
          "scale_mids": np.concatenate(all_scale_mids, axis=0),
      }
      if prefix == "mpi":
          auc_val, pckh5 = calc_auc(
              np.concatenate(pred_3ds, axis=0),
              np.concatenate(gt_3ds, axis=0),
          )
          auc_val_p2, pckh5_p2 = calc_auc_aligned(
              np.concatenate(pred_3ds, axis=0),
              np.concatenate(gt_3ds, axis=0),
          )
          all_out_data["auc"] = auc_val
          all_out_data["pckh5"] = pckh5
          all_out_data["auc_p2"] = auc_val_p2
          all_out_data["pckh5_p2"] = pckh5_p2
      del pred_3ds, gt_3ds
  
      return all_out_data
  
file_path: insightface/body/human_pose/ambiguity_aware/lib/core/function2.py
imports: import time
  import pickle
  import os.path
  import numpy
  import torch
  import torch.nn.functional
  import os
  from tqdm import tqdm
  from itertools import permutations
  from lib.core.loss import *
  from lib.utils.vis import vis_joints
  from lib.utils.utils import p_mpjpe, rotate, calc_auc, calc_auc_aligned
label_desc: Use image node_id 3 for calling a global function with example usage: evaluate(val_loader, pose_model, config, is_train) and returns: all_out_data