MMFMChallenge / backup /utils /prepare_test_submission_file.py
wlin21at's picture
update private data sample ids
33dd4ea
raw
history blame
2.83 kB
import json
import csv
if __name__ == '__main__':
# category_to_sample_ids_dict = json.load(open('../category_to_sample_ids_dict.json'))
# answer_dict_for_mixtral_eval = json.load(open('../answer_dict_for_mixtral_eval.json'))
model_name = 'llava1.5_7b'
# model_name = 'llava1.5_13b'
submission_file_phase1_6datasets = f'/system/user/publicdata/LMM_benchmarks/MMFM_challenge_final/doc-vl-eval/inference_results/output_6_datasets_{model_name}.json'
submission_file_phase1_4datasets = f'/system/user/publicdata/LMM_benchmarks/MMFM_challenge_final/doc-vl-eval/inference_results/output_4_datasets_{model_name}.json'
submission_file_phase2 = f'/system/user/publicdata/LMM_benchmarks/MMFM_challenge_final/doc-vl-eval/inference_results/output_private_{model_name}.json'
submission_file = f'test_submission_{model_name}.csv'
# answer_dict_file = '/system/user/publicdata/LMM_benchmarks/MMFM_challenge_final/doc-vl-eval/answer_dicts/coverted_output_test_all_datasets.json'
answer_dict_file_phase1 = '/system/user/publicdata/LMM_benchmarks/MMFM_challenge_final/doc-vl-eval/answer_dicts/coverted_output_test_all_datasets.json'
answer_dict_file_phase2 = '/system/user/publicdata/LMM_benchmarks/MMFM_challenge_final/doc-vl-eval/answer_dicts/converted_output_test_private_for_mixtral_eval.json'
with open(answer_dict_file_phase1, 'r') as f:
answer_dict_phase1 = json.load(f) # 2000 samples, 200 samples x 10 datasets
with open(answer_dict_file_phase2, 'r') as f:
answer_dict_phase2 = json.load(f)
submission_phase1_6datasets = json.load(open(submission_file_phase1_6datasets))
submission_phase1_4datasets = json.load(open(submission_file_phase1_4datasets))
submission_phase2 = json.load(open(submission_file_phase2))
answer_dict = {**answer_dict_phase1, **answer_dict_phase2}
merged_submission = {**submission_phase1_6datasets, **submission_phase1_4datasets, **submission_phase2}
# answer_dict = { **answer_dict_phase2}
# merged_submission = {**submission_phase2}
merged_submission_ = {}
for key, value in merged_submission.items():
items = key.split('_')
if items[0] == 'mychart':
items = items[:3] + [items[-1]]
elif items[0] == 'myinfographic':
items = items[:2] + [items[-1]]
key_ = '_'.join(items[:-1])
merged_submission_[key_] = value
with open(submission_file, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['id', 'pred', 'split'])
# idx = 0
for sample_key, data_dict in answer_dict.items():
items = sample_key.split('_')
id_ = '_'.join(items[:-1])
pred = merged_submission_[id_]
writer.writerow([id_, pred, 'public'])
# idx += 1
t = 1