# 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: dataset/pose_dataset.py
# class Batch(Enum):
#     inputs = 0
#     part_score_targets = 1
#     part_score_weights = 2
#     locref_targets = 3
#     locref_mask = 4
#     pairwise_targets = 5
#     pairwise_mask = 6
#     data_item = 7


import numpy as np
import scipy.io
from util.config import load_config
from dataset.factory import create as create_dataset
from dataset.pose_dataset import Batch
    mat_stats["means"] = []
    mat_stats["std_devs"] = []
    for start in range(cfg.num_joints):
        for end in range(cfg.num_joints):
            if start != end:
                joint_pair = (start, end)
                mat_stats["graph"].append([start, end])
                mat_stats["means"].append(stats[joint_pair]["mean"])
                mat_stats["std_devs"].append(stats[joint_pair]["std"])
    print(mat_stats)
    scipy.io.savemat(cfg.pairwise_stats_fn, mat_stats)


# Compute pairwise statistics at reference scale
def pairwise_stats():
    cfg = load_config()
    dataset = create_dataset(cfg)
    dataset.set_shuffle(True)
    dataset.set_pairwise_stats_collect(True)

    num_images = dataset.num_images
    all_pairwise_differences = {}

    if cfg.mirror:
        num_images *= 2

    for k in range(num_images):
        print('processing image {}/{}'.format(k, num_images-1))

        batch = dataset.next_batch()

# 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: dataset/pose_dataset.py
# class Batch(Enum):
#     inputs = 0
#     part_score_targets = 1
#     part_score_weights = 2
#     locref_targets = 3
#     locref_mask = 4
#     pairwise_targets = 5
#     pairwise_mask = 6
#     data_item = 7


# Path: pairwise_stats.py
import numpy as np
import scipy.io
from util.config import load_config
from dataset.factory import create as create_dataset
from dataset.pose_dataset import Batch

    mat_stats["means"] = []
    mat_stats["std_devs"] = []
    for start in range(cfg.num_joints):
        for end in range(cfg.num_joints):
            if start != end:
                joint_pair = (start, end)
                mat_stats["graph"].append([start, end])
                mat_stats["means"].append(stats[joint_pair]["mean"])
                mat_stats["std_devs"].append(stats[joint_pair]["std"])
    print(mat_stats)
    scipy.io.savemat(cfg.pairwise_stats_fn, mat_stats)


# Compute pairwise statistics at reference scale
def pairwise_stats():
    cfg = load_config()
    dataset = create_dataset(cfg)
    dataset.set_shuffle(True)
    dataset.set_pairwise_stats_collect(True)

    num_images = dataset.num_images
    all_pairwise_differences = {}

    if cfg.mirror:
        num_images *= 2

    for k in range(num_images):
        print('processing image {}/{}'.format(k, num_images-1))

        batch = dataset.next_batch()

        batch_stats = batch[Batch.data_item].pairwise_stats