# Path: util/config.py
# def load_config(filename = "pose_cfg.yaml"):
#     if 'POSE_PARAM_PATH' in os.environ:
#         filename = os.environ['POSE_PARAM_PATH'] + '/' + filename
#     return cfg_from_file(filename)
# 
# Path: dataset/factory.py
# def create(cfg):
#     dataset_type = cfg.dataset_type
#     if dataset_type == "mpii":
#         from dataset.mpii import MPII
#         data = MPII(cfg)
#     elif dataset_type == "coco":
#         from dataset.mscoco import MSCOCO
#         data = MSCOCO(cfg)
#     elif dataset_type == "penn_action":
#         from dataset.penn_action import PennAction
#         data = PennAction(cfg)
#     elif dataset_type == "default":
#         data = PoseDataset(cfg)
#     else:
#         raise Exception("Unsupported dataset_type: \"{}\"".format(dataset_type))
#     return data


import argparse
import numpy as np
import scipy.io as sio
from numpy import array as arr
from util.config import load_config
from dataset.factory import create as dataset_create
    for k in range(num_images):
        pred = joints[0,k]
        gt = dataset.data[k].joints[0]
        if gt.shape[0] == 0:
            continue
        gt_joint_ids = gt[:, 0].astype('int32')
        rect = enclosing_rect(gt[:,1:3])
        pck_thresh[k] = pck_ratio_thresh*np.amax(rect_size(rect))

        gt_present_joints[k, gt_joint_ids] = 1
        gt_joints[k, gt_joint_ids, :] = gt[:,1:3]
        pred_joints[k, :, :] = pred[:,0:2]

    dists = np.sqrt(np.sum((pred_joints - gt_joints)**2, axis=2))
    correct = dists <= pck_thresh

    num_all = np.sum(gt_present_joints, axis=0)

    num_correct = np.zeros((num_joints, ))
    for j_id in range(num_joints):
        num_correct[j_id] = np.sum(correct[gt_present_joints[:,j_id] == 1, j_id], axis=0)

    pck = num_correct/num_all*100.0

    print_results(pck, cfg)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    args, unparsed = parser.parse_known_args()


# Path: util/config.py
# def load_config(filename = "pose_cfg.yaml"):
#     if 'POSE_PARAM_PATH' in os.environ:
#         filename = os.environ['POSE_PARAM_PATH'] + '/' + filename
#     return cfg_from_file(filename)
# 
# Path: dataset/factory.py
# def create(cfg):
#     dataset_type = cfg.dataset_type
#     if dataset_type == "mpii":
#         from dataset.mpii import MPII
#         data = MPII(cfg)
#     elif dataset_type == "coco":
#         from dataset.mscoco import MSCOCO
#         data = MSCOCO(cfg)
#     elif dataset_type == "penn_action":
#         from dataset.penn_action import PennAction
#         data = PennAction(cfg)
#     elif dataset_type == "default":
#         data = PoseDataset(cfg)
#     else:
#         raise Exception("Unsupported dataset_type: \"{}\"".format(dataset_type))
#     return data


# Path: eval_pck.py
import argparse
import numpy as np
import scipy.io as sio
from numpy import array as arr
from util.config import load_config
from dataset.factory import create as dataset_create

    for k in range(num_images):
        pred = joints[0,k]
        gt = dataset.data[k].joints[0]
        if gt.shape[0] == 0:
            continue
        gt_joint_ids = gt[:, 0].astype('int32')
        rect = enclosing_rect(gt[:,1:3])
        pck_thresh[k] = pck_ratio_thresh*np.amax(rect_size(rect))

        gt_present_joints[k, gt_joint_ids] = 1
        gt_joints[k, gt_joint_ids, :] = gt[:,1:3]
        pred_joints[k, :, :] = pred[:,0:2]

    dists = np.sqrt(np.sum((pred_joints - gt_joints)**2, axis=2))
    correct = dists <= pck_thresh

    num_all = np.sum(gt_present_joints, axis=0)

    num_correct = np.zeros((num_joints, ))
    for j_id in range(num_joints):
        num_correct[j_id] = np.sum(correct[gt_present_joints[:,j_id] == 1, j_id], axis=0)

    pck = num_correct/num_all*100.0

    print_results(pck, cfg)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    args, unparsed = parser.parse_known_args()


    cfg = load_config()