| import pandas as pd | |
| import jsonlines | |
| import re | |
| import random | |
| def convert_excel_to_json(excel_file, json_file): | |
| df = pd.read_excel(excel_file) | |
| df = df.where(pd.notnull(df), None) | |
| df.to_json(json_file, orient='records', lines=True, default_handler=str) | |
| def count_bbox(answer: str): | |
| PATTERN = re.compile(r'\((.*?)\),\((.*?)\)') | |
| bbox_num = len(re.findall(PATTERN, answer)) | |
| return bbox_num | |
| xlsx_input = 'public_eval/bbox_step_300/MathVerse_MINI/20250418/bbox_step_300/bbox_step_300_MathVerse_MINI.xlsx' | |
| json_output = xlsx_input.replace('.xlsx', '.jsonl') | |
| convert_excel_to_json(xlsx_input, json_output) | |
| box_output = [] | |
| with jsonlines.open(json_output, 'r') as reader: | |
| for obj in reader: | |
| total_num = 0 | |
| total_bbox_num = 0 | |
| bbox_sample_num = 0 | |
| for obj in reader: | |
| total_num += 1 | |
| answer = obj["full_prediction"] | |
| bbox_num = count_bbox(answer) | |
| total_bbox_num += bbox_num | |
| if bbox_num > 0: | |
| bbox_sample_num += 1 | |
| box_output.append(obj) | |
| random.shuffle(box_output) | |
| with jsonlines.open(json_output.replace('.jsonl', '_bbox.jsonl'), 'w') as writer: | |
| for obj in box_output: | |
| writer.write(obj) | |
| print(f"total_num: {total_num}, total_bbox_num: {total_bbox_num}, bbox_sample_num: {bbox_sample_num}") | |
| print(f"average box num: {total_bbox_num / bbox_sample_num}, bbox num ratio: {bbox_sample_num / total_num}") | |