def validate_data(gtFilePath, submFilePath):
    """
    Method validate_data: validates that all files in the results folder are correct (have the correct name contents).
                            Validates also that there are no missing files in the folder.
                            If some error detected, the method raises the error
    """

    gtJson = json.load(open(gtFilePath, 'rb'))
    submJson = json.load(open(submFilePath, 'rb'))

    if 'data' not in gtJson:
        raise Exception('The GT file is not valid (no data key)')

    if 'dataset_name' not in gtJson:
        raise Exception('The GT file is not valid (no dataset_name key)')

    if isinstance(submJson, list) is False:
        raise Exception('The Det file is not valid (root item must be an array)')

    if len(submJson) != len(gtJson['data']):
        raise Exception('The Det file is not valid (invalid number of answers. Expected:' + str(
            len(gtJson['data'])) + ' Found:' + str(len(submJson)) + ')')

    gtQuestions = sorted([r['questionId'] for r in gtJson['data']])
    res_id_to_index = {int(r['questionId']): ix for ix, r in enumerate(submJson)}
    detQuestions = sorted([r['questionId'] for r in submJson])

    if ((gtQuestions == detQuestions) is False):
        raise Exception('The Det file is not valid. Question IDs must much GT')

    for gtObject in gtJson['data']:

        try:
            q_id = int(gtObject['questionId'])
            res_ix = res_id_to_index[q_id]

        except:
            raise Exception('The Det file is not valid. Question ' + str(gtObject['questionId']) + ' not present')

        else:
            detObject = submJson[res_ix]

            #            if detObject['questionId'] != gtObject['questionId'] :
            #                raise Exception("Answer #" + str(i) + " not valid (invalid question ID. Expected:" + str(gtObject['questionId']) + "Found:" + detObject['questionId'] + ")")

            if 'answer' not in detObject:
                raise Exception('Question ' + str(gtObject['questionId']) + ' not valid (no answer key)')

            if isinstance(detObject['answer'], list) is True:
                raise Exception(
                    'Question ' + str(gtObject['questionId']) + ' not valid (answer key has to be a single string)')

    Method validate_data: validates that all files in the results folder are correct (have the correct name contents).
                            Validates also that there are no missing files in the folder.
                            If some error detected, the method raises the error
    
internvl_chat/eval/mpdocvqa/infographicsvqa_eval.py