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
      pose_model.eval()
      center_idx = int((num_frames - 1) / 2)
      valid_cnt = 0
      test3d_loss_total_p1, test3d_loss_total_p2 = 0.0, 0.0
      root_idx = 13 if config.DATA.NUM_JOINTS == 17 else 12
      pred_3ds, gt_3ds, all_scales, all_scale_mids = [], [], [], []
      prefix = config.DATA.DATASET_NAME
      if is_train:
          if prefix == "surreal":
              factor = 0.563642
          else:
              factor = 0.6451607 if prefix == "h36m" else 0.728695902
      else:
          if prefix == "surreal":
              factor = 0.56071004
          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')
      # exclude spine: 14, neck: 15
      # joint_indices = list(range(14)) + [16]
      with torch.no_grad():
          t = tqdm(val_loader, desc=f"Evaluating...")
          for kp2ds_, kp3ds, rot, _, _, _ in t:
              if valid_cnt == 0:
                  bs = kp2ds_.size(0)
              kp2ds = kp2ds_.cuda()
              kp3ds = kp3ds.cuda()
              rot = rot.cuda()
              pred_3d, scales, scale_mids = pose_model(
                  kp2ds, is_train=False, rot=rot
              )
              root3d, root3d_pred = (
                  kp3ds[:, root_idx : root_idx + 1].clone(),
                  pred_3d[:, root_idx : root_idx + 1].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(),
              )
              pred_3ds.append(pred_numpy)
              gt_3ds.append(gt_numpy)
              if scales is not None:
                  scales = scales.cpu().numpy()
                  all_scales.append(scales)
              if scale_mids is not None:
                  scale_mids = scale_mids.cpu().numpy()
                  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
              )
              if err_p1 > 10000.0:
                  import ipdb
  
                  ipdb.set_trace()
              # err_p2 = p_mpjpe(pred_numpy[:, joint_indices], gt_numpy[:, joint_indices]) * 1000.0
              err_p2 = p_mpjpe(pred_numpy, gt_numpy) * 1000.0
              test3d_loss_total_p1 += err_p1
              test3d_loss_total_p2 += err_p2
              valid_cnt += 1
      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),
      }
      if len(all_scales) > 0:
          all_out_data["scales"] = np.concatenate(all_scales, axis=0)
      if len(all_scale_mids) > 0:
          all_out_data["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/function1.py
imports: import time
  import pickle
  import os.path
  import numpy
  import torch
  import torch.nn.functional
  import os
  from tqdm import tqdm
  from lib.core.loss import *
  from lib.utils.vis import vis_joints
  from lib.utils.utils import p_mpjpe, get_pck3d, 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