File size: 1,450 Bytes
b5beb60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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}")