def load_testset(data_root, out_dir, valid_only=True):
    """Load testing data, create annotation file and camera file.

    Args:
        data_root: Directory of dataset.
        out_dir: Directory to save annotation file.
        valid_only: Only keep frames with valid_label == 1.
    """
    _imgnames = []
    _centers = []
    _scales = []
    _joints_2d = []
    _joints_3d = []
    cameras = {}

    img_dir = join(out_dir, 'images')
    os.makedirs(img_dir, exist_ok=True)
    annot_dir = join(out_dir, 'annotations')
    os.makedirs(annot_dir, exist_ok=True)

    for subj in test_subjects:
        subj_path = join(data_root, 'test', f'TS{subj}')
        num_frames = test_frame_nums[subj]

        # load annotations
        annot_file = os.path.join(subj_path, 'annot_data.mat')
        with h5py.File(annot_file, 'r') as fin:
            annot2 = np.array(fin['annot2']).reshape((-1, 17, 2))
            annot3 = np.array(fin['annot3']).reshape((-1, 17, 3))
            valid = np.array(fin['valid_frame']).reshape(-1)

        # manually estimate camera intrinsics
        fx, cx = np.linalg.lstsq(
            annot3[:, :, [0, 2]].reshape((-1, 2)),
            (annot2[:, :, 0] * annot3[:, :, 2]).reshape(-1, 1),
            rcond=None)[0].flatten()
        fy, cy = np.linalg.lstsq(
            annot3[:, :, [1, 2]].reshape((-1, 2)),
            (annot2[:, :, 1] * annot3[:, :, 2]).reshape(-1, 1),
            rcond=None)[0].flatten()
        if subj <= 4:
            w, h = 2048, 2048
        else:
            w, h = 1920, 1080
        cameras[f'TS{subj}'] = dict(
            c=np.array([[cx], [cy]]),
            f=np.array([[fx], [fy]]),
            w=w,
            h=h,
            name=f'test_cam_{subj}')

        # get annotations
        if valid_only:
            valid_frames = np.nonzero(valid)[0]
        else:
            valid_frames = np.arange(num_frames)
        joints_2d = annot2[valid_frames, :, :]
        joints_3d = annot3[valid_frames, :, :] * 0.001

        centers, scales, joints_2d, joints_3d = get_annotations(
            joints_2d, joints_3d)
        _centers.append(centers)
        _scales.append(scales)
        _joints_2d.append(joints_2d)
        _joints_3d.append(joints_3d)

        # copy and rename images
        for i in valid_frames:
            imgname = f'TS{subj}_{i+1:06d}.jpg'
            shutil.copyfile(
                join(subj_path, 'imageSequence', f'img_{i+1:06d}.jpg'),
                join(img_dir, imgname))
            _imgnames.append(imgname)

    _imgnames = np.array(_imgnames)
    _centers = np.concatenate(_centers)
    _scales = np.concatenate(_scales)
    _joints_2d = np.concatenate(_joints_2d)
    _joints_3d = np.concatenate(_joints_3d)

    if valid_only:
        out_file = join(annot_dir, 'mpi_inf_3dhp_test_valid.npz')
    else:
        out_file = join(annot_dir, 'mpi_inf_3dhp_test_all.npz')
    np.savez(
        out_file,
        imgname=_imgnames,
        center=_centers,
        scale=_scales,
        part=_joints_2d,
        S=_joints_3d)
    print(f'Create annotation file for testset: {out_file}. '
          f'{len(_imgnames)} samples in total.')

    out_file = join(annot_dir, 'cameras_test.pkl')
    with open(out_file, 'wb') as fout:
        pickle.dump(cameras, fout)
    print(f'Create camera file for testset: {out_file}.')
Load testing data, create annotation file and camera file.

    Args:
        data_root: Directory of dataset.
        out_dir: Directory to save annotation file.
        valid_only: Only keep frames with valid_label == 1.
    
mmpose/tools/dataset_converters/preprocess_mpi_inf_3dhp.py