# 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)


import os
import sys
import argparse
import json
from util.config import load_config
from pycocotools.coco import COCO as COCO
from pycocotools.cocoeval import COCOeval
def eval_init(cfg):
    dataset = cfg.dataset
    dataset_phase = cfg.dataset_phase
    dataset_ann = cfg.dataset_ann
    threshold = 0

    # initialize cocoGT api
    annFile = '%s/annotations/%s_%s.json' % (dataset, dataset_ann, dataset_phase)
    cocoGT = COCO(annFile)

    # initialize cocoPred api
    inFile = "predictions_with_segm.json"
    predFile = apply_threhsold(inFile, threshold)
    cocoPred = cocoGT.loadRes(predFile)

    return cocoGT, cocoPred


def eval_mscoco_with_segm(cocoGT, cocoPred):
    # running evaluation
    cocoEval = COCOeval(cocoGT, cocoPred, "keypoints")
    cocoEval.evaluate()
    cocoEval.accumulate()
    cocoEval.summarize()


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: eval_mscoco.py
import os
import sys
import argparse
import json
from util.config import load_config
from pycocotools.coco import COCO as COCO
from pycocotools.cocoeval import COCOeval

def eval_init(cfg):
    dataset = cfg.dataset
    dataset_phase = cfg.dataset_phase
    dataset_ann = cfg.dataset_ann
    threshold = 0

    # initialize cocoGT api
    annFile = '%s/annotations/%s_%s.json' % (dataset, dataset_ann, dataset_phase)
    cocoGT = COCO(annFile)

    # initialize cocoPred api
    inFile = "predictions_with_segm.json"
    predFile = apply_threhsold(inFile, threshold)
    cocoPred = cocoGT.loadRes(predFile)

    return cocoGT, cocoPred


def eval_mscoco_with_segm(cocoGT, cocoPred):
    # running evaluation
    cocoEval = COCOeval(cocoGT, cocoPred, "keypoints")
    cocoEval.evaluate()
    cocoEval.accumulate()
    cocoEval.summarize()


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


    cfg = load_config()