CoolFace
Apppublic

LanguageBind/Video-LLaVA

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
234likes
convert_vizwiz_for_submission.py48 linesDownload Raw Back to scripts
1import os2import argparse3import json4 5from llava.eval.m4c_evaluator import EvalAIAnswerProcessor6 7 8def parse_args():9    parser = argparse.ArgumentParser()10    parser.add_argument('--annotation-file', type=str, required=True)11    parser.add_argument('--result-file', type=str, required=True)12    parser.add_argument('--result-upload-file', type=str, required=True)13    return parser.parse_args()14 15 16if __name__ == '__main__':17 18    args = parse_args()19 20    os.makedirs(os.path.dirname(args.result_upload_file), exist_ok=True)21 22    results = []23    error_line = 024    for line_idx, line in enumerate(open(args.result_file)):25        try:26            results.append(json.loads(line))27        except:28            error_line += 129    results = {x['question_id']: x['text'] for x in results}30    test_split = [json.loads(line) for line in open(args.annotation_file)]31    split_ids = set([x['question_id'] for x in test_split])32 33    print(f'total results: {len(results)}, total split: {len(test_split)}, error_line: {error_line}')34 35    all_answers = []36 37    answer_processor = EvalAIAnswerProcessor()38 39    for x in test_split:40        assert x['question_id'] in results41        all_answers.append({42            'image': x['image'],43            'answer': answer_processor(results[x['question_id']])44        })45 46    with open(args.result_upload_file, 'w') as f:47        json.dump(all_answers, f)48