BruceFeng98 commited on
Commit
bf74572
·
verified ·
1 Parent(s): 6342ddc

Upload metric.py

Browse files
Files changed (1) hide show
  1. metric/metric.py +1130 -0
metric/metric.py ADDED
@@ -0,0 +1,1130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ import re
4
+ import math
5
+ import statistics
6
+
7
+ def read_json_file(file_path):
8
+ """
9
+ Reads a JSON file and returns the parsed data as a Python object.
10
+
11
+ :param file_path: The path to the JSON file
12
+ :return: The data parsed from the JSON file
13
+ """
14
+ with open(file_path, 'r', encoding='utf-8') as f:
15
+ data = json.load(f)
16
+ return data
17
+
18
+ def clean_string(s: str) -> str:
19
+ """
20
+ Remove all non-alphanumeric characters from the input string,
21
+ including punctuation, whitespace, and escape characters.
22
+
23
+ :param s: The original string.
24
+ :return: A new string containing only letters and digits.
25
+ """
26
+ # Replace any character that is NOT a letter or digit with ''
27
+ return re.sub(r'[^A-Za-z0-9]+', '', s)
28
+
29
+ def word_level_ac(texts, response, window_size: int = 5, step: int = 5):
30
+ if isinstance(texts, list):
31
+ gt = ""
32
+ for item in texts:
33
+ gt += clean_string(item)
34
+ if isinstance(texts, str):
35
+ gt = clean_string(texts)
36
+
37
+ if isinstance(response, list):
38
+ ocr = ""
39
+ for item in response:
40
+ ocr += clean_string(item)
41
+ if isinstance(response, str):
42
+ ocr = clean_string(response)
43
+
44
+ results = []
45
+ n = len(gt)
46
+ for i in range(0, n - window_size + 1, step):
47
+ substr = gt[i: i + window_size]
48
+ found = substr in ocr
49
+ # print(found)
50
+ results.append(found)
51
+ if not results:
52
+ print(0.0)
53
+ return 0.0
54
+
55
+ ac = sum(results) / len(results)
56
+ # print(ac)
57
+ return ac
58
+
59
+ def logo_ocr_ac(texts, response):
60
+ if isinstance(texts, list):
61
+ gt = ""
62
+ for item in texts:
63
+ gt += clean_string(item)
64
+ if isinstance(texts, str):
65
+ gt = clean_string(texts)
66
+
67
+ if isinstance(response, list):
68
+ ocr = ""
69
+ for item in response:
70
+ ocr += clean_string(item)
71
+ if isinstance(response, str):
72
+ ocr = clean_string(response)
73
+
74
+ lower_gt = gt.lower()
75
+ lower_ocr = ocr.lower()
76
+
77
+ if lower_gt==lower_ocr:
78
+ return 1
79
+ else:
80
+ return 0
81
+
82
+ def real_poster_ac(texts, response, word_mode = False):
83
+ if isinstance(texts, list):
84
+ gt = []
85
+ for item in texts:
86
+ gt.append(clean_string(item).lower())
87
+ if isinstance(texts, str):
88
+ gt = [clean_string(texts).lower()]
89
+
90
+ if isinstance(response, list):
91
+ ocr = ""
92
+ for item in response:
93
+ ocr += clean_string(item).lower()
94
+ if isinstance(response, str):
95
+ ocr = clean_string(response).lower()
96
+
97
+ if word_mode == False:
98
+ results = []
99
+ for i in range(0,len(gt)):
100
+ substr = gt[i]
101
+ if substr in ocr:
102
+ found = 1
103
+ results.append(found)
104
+ else:
105
+ found = 0
106
+ results.append(found)
107
+
108
+ ac = sum(results)/len(results)
109
+
110
+ if word_mode==True:
111
+ ac = word_level_ac(gt, ocr)
112
+
113
+ return ac
114
+
115
+ def font_matching_ac(options, response):
116
+ if isinstance(options, list):
117
+ gt = ""
118
+ for item in options:
119
+ gt += (clean_string(item))
120
+ if isinstance(options, str):
121
+ gt = clean_string(options)
122
+
123
+ if isinstance(response, list):
124
+ answer = ""
125
+ for item in response:
126
+ answer += clean_string(item)
127
+ if isinstance(response, str):
128
+ answer = clean_string(response)
129
+
130
+ if len(answer) > 20:
131
+ return 0
132
+
133
+ if gt in answer:
134
+ return 1
135
+ else:
136
+ return 0
137
+
138
+ def font_attr_ac(options, response):
139
+ if isinstance(options, list):
140
+ gt = ""
141
+ for item in options:
142
+ gt += (clean_string(item))
143
+ if isinstance(options, str):
144
+ gt = clean_string(options)
145
+
146
+ if isinstance(response, list):
147
+ answer = ""
148
+ for item in response:
149
+ answer += clean_string(item)
150
+ if isinstance(response, str):
151
+ answer = clean_string(response)
152
+
153
+ # if len(answer)>20:
154
+ # return 0
155
+
156
+ if gt in answer:
157
+ return 1
158
+ else:
159
+ return 0
160
+
161
+
162
+ def font_effect_ac(options, response):
163
+ if isinstance(options, list):
164
+ gt = ""
165
+ for item in options:
166
+ gt += (clean_string(item))
167
+ if isinstance(options, str):
168
+ gt = clean_string(options)
169
+
170
+ if isinstance(response, list):
171
+ answer = ""
172
+ for item in response:
173
+ answer += clean_string(item)
174
+ if isinstance(response, str):
175
+ answer = clean_string(response)
176
+
177
+ # if len(answer)>20:
178
+ # return 0
179
+
180
+ if gt in answer:
181
+ return 1
182
+ else:
183
+ return 0
184
+
185
+ def font_effect_2_ac(options: list, response):
186
+ if isinstance(response, list):
187
+ answer = ""
188
+ for item in response:
189
+ answer += clean_string(item)
190
+ if isinstance(response, str):
191
+ answer = clean_string(response)
192
+
193
+ if options[0] in answer:
194
+ color_ac = 1
195
+ else:
196
+ color_ac = 0
197
+
198
+ result = []
199
+ for i in range(1,len(options)):
200
+ found = options[i] in answer
201
+ result.append(found)
202
+ if len(result)==0:
203
+ return color_ac, None
204
+ effect_ac = sum(result)/len(result)
205
+ # if len(answer)>20:
206
+ # return 0
207
+
208
+ return color_ac, effect_ac
209
+
210
+
211
+ def layout_comparison_ac(gt, response):
212
+ if isinstance(response, list):
213
+ answer = ""
214
+ for item in response:
215
+ answer += clean_string(item)
216
+ if isinstance(response, str):
217
+ answer = clean_string(response)
218
+
219
+ if gt in answer:
220
+ return 1
221
+ else:
222
+ return 0
223
+
224
+ def extract_numbers(s):
225
+
226
+ return [int(num) for num in re.findall(r'\d+', s)]
227
+
228
+ def extract_numbers_float(s):
229
+
230
+ numbers = []
231
+ for num_str in re.findall(r'\d+\.\d+|\d+', s): # 匹配小数或整数
232
+ if '.' in num_str:
233
+ numbers.append(float(num_str))
234
+ else:
235
+ numbers.append(int(num_str))
236
+ return numbers
237
+
238
+ def extract_numbers_float2(s):
239
+ """提取字符串中的所有浮点数(小数),忽略整数"""
240
+ numbers = []
241
+ for num_str in re.findall(r'\d+\.\d+', s): # 只匹配小数(必须包含小数点)
242
+ numbers.append(float(num_str))
243
+ return numbers
244
+ def group_numbers_into_fours(num_list):
245
+ """
246
+
247
+ """
248
+ n = len(num_list)
249
+
250
+
251
+ result = [num_list[i:i + 4] for i in range(0, n-3, 4)]
252
+ return result
253
+
254
+ def clean_string_for_box(input_str):
255
+ # 正则表达式匹配:保留方括号 []、数字、空格和逗号
256
+ return re.sub(r'[^\[\], .\d]', '', input_str)
257
+ def parse_bbox_string(bbox_str):
258
+
259
+ """
260
+ """
261
+ try:
262
+ # 使用literal_eval将字符串解析为Python对象
263
+ bbox_str = clean_string_for_box(bbox_str)
264
+ bbox_nums = extract_numbers_float(bbox_str)
265
+ bboxes = group_numbers_into_fours(bbox_nums)
266
+ # bboxes = ast.literal_eval(bbox_str)
267
+ return bboxes
268
+ except Exception as e:
269
+ print("解析bbox字符串时出错:", e)
270
+ return []
271
+
272
+ def parse_bbox_string2(bbox_str):
273
+
274
+ """
275
+ """
276
+ try:
277
+
278
+ bbox_str = clean_string_for_box(bbox_str)
279
+ bbox_nums = extract_numbers_float2(bbox_str)
280
+ bboxes = group_numbers_into_fours(bbox_nums)
281
+ # bboxes = ast.literal_eval(bbox_str)
282
+ return bboxes
283
+ except Exception as e:
284
+ print("解析bbox字符串时出错:", e)
285
+ return []
286
+
287
+ def calculate_iou(box1, box2):
288
+ """
289
+ """
290
+
291
+
292
+ x1_1, y1_1, x2_1, y2_1 = box1
293
+ x1_2, y1_2, x2_2, y2_2 = box2
294
+
295
+ # 计算交集区域坐标
296
+ x_left = max(x1_1, x1_2)
297
+ y_top = max(y1_1, y1_2)
298
+ x_right = min(x2_1, x2_2)
299
+ y_bottom = min(y2_1, y2_2)
300
+
301
+ if x1_1 > x2_1: return 0.0
302
+ if y1_1 > y2_1: return 0.0
303
+
304
+ if x1_2 > x2_2: return 0.0
305
+ if y1_2 > y2_2: return 0.0
306
+
307
+
308
+ if x_right < x_left or y_bottom < y_top:
309
+ return 0.0
310
+
311
+
312
+ intersection_area = (x_right - x_left) * (y_bottom - y_top)
313
+
314
+
315
+ box1_area = (x2_1 - x1_1) * (y2_1 - y1_1)
316
+ box2_area = (x2_2 - x1_2) * (y2_2 - y1_2)
317
+
318
+
319
+ union_area = box1_area + box2_area - intersection_area
320
+
321
+
322
+ iou = intersection_area / union_area
323
+ return iou
324
+
325
+ def calculate_centerpoint(norm_gt_bboxs, norm_pre_bbox):
326
+ x1_1, y1_1, x2_1, y2_1 = norm_gt_bboxs
327
+ x1_2, y1_2, x2_2, y2_2 = norm_pre_bbox
328
+
329
+ cx1 = (x1_1 + x2_1) / 2.0
330
+ cy1 = (y1_1 + y2_1) / 2.0
331
+
332
+ # 计算第二个框的中心
333
+ cx2 = (x1_2 + x2_2) / 2.0
334
+ cy2 = (y1_2 + y2_2) / 2.0
335
+
336
+ # 欧氏距离
337
+ dist = math.hypot(cx1 - cx2, cy1 - cy2)
338
+
339
+ return dist
340
+
341
+ def calculate_area_ratio(box1, box2):
342
+ """
343
+ """
344
+
345
+
346
+ x1_1, y1_1, x2_1, y2_1 = box1
347
+ x1_2, y1_2, x2_2, y2_2 = box2
348
+
349
+ # 计算各自面积
350
+ box1_area = (x2_1 - x1_1) * (y2_1 - y1_1)
351
+ box2_area = (x2_2 - x1_2) * (y2_2 - y1_2)
352
+ if box1_area <= 0:
353
+ raise
354
+ if box2_area <= 0:
355
+ return 0.0
356
+
357
+ return box1_area/ box2_area
358
+
359
+
360
+
361
+ def denorm_bbox(norm_bbox,size):
362
+ bbox = [0,0,0,0]
363
+ width,height = size
364
+ bbox[0] = int(norm_bbox[0] * width)
365
+ bbox[1] = int(norm_bbox[1] * height)
366
+ bbox[2] = int(norm_bbox[2] * width)
367
+ bbox[3] = int(norm_bbox[3] * height)
368
+ return bbox
369
+
370
+ def norm_bbox(norm_bbox,size):
371
+ bbox = [0,0,0,0]
372
+ width,height = size
373
+ bbox[0] = (norm_bbox[0] / width)
374
+ bbox[1] = (norm_bbox[1] / height)
375
+ bbox[2] = (norm_bbox[2] / width)
376
+ bbox[3] = (norm_bbox[3] / height)
377
+ return bbox
378
+
379
+ def bbox_number_types(bboxes):
380
+ """
381
+
382
+ """
383
+ result = []
384
+ for box in bboxes:
385
+ types = []
386
+ for num in box:
387
+ # 如果它和自身取整后相等,就当作整数
388
+ if isinstance(num, (int,)) or (isinstance(num, float) and num.is_integer()):
389
+ types.append("int")
390
+ else:
391
+ types.append("float")
392
+ result.append(types)
393
+ return result
394
+
395
+
396
+
397
+ def task_4_ocr(data):
398
+ """ character ocr and words ocr """
399
+ pure_char_ocr = []
400
+ colorful_char_ocr = []
401
+ pure_words_ocr = []
402
+ colorful_words_ocr = []
403
+ for item in data:
404
+ if item["task"] == "pure_char ocr":
405
+ gt = item["gt"]
406
+ response = item["response"]
407
+ # if word_level_ac(gt, response) < 0.1:
408
+ # # print(response)
409
+ # continue
410
+ pure_char_ocr.append(word_level_ac(gt, response))
411
+
412
+ if item["task"] == "colorful_char ocr":
413
+ gt = item["gt"]
414
+ response = item["response"]
415
+ # if word_level_ac(gt, response) < 0.1:
416
+ # # print(response)
417
+ # continue
418
+ colorful_char_ocr.append(word_level_ac(gt, response))
419
+
420
+ if item["task"] == "pure_words ocr":
421
+ gt = item["gt"]
422
+ response = item["response"]
423
+ # if word_level_ac(gt, response) < 0.1:
424
+ # # print(response)
425
+ # continue
426
+ pure_words_ocr.append(word_level_ac(gt, response))
427
+ if item["task"] == "colorful_words ocr":
428
+ gt = item["gt"]
429
+ response = item["response"]
430
+ # if word_level_ac(gt, response)<0.1:
431
+ # # print(response)
432
+ # continue
433
+ colorful_words_ocr.append(word_level_ac(gt, response))
434
+
435
+ print("pure_char_ocr word-level accuracy: ", f"{sum(pure_char_ocr)/len(pure_char_ocr):.3f}", f" total imgs:{len(pure_char_ocr)/400}")
436
+ print("colorful_char_ocr word-level accuracy: ", f"{sum(colorful_char_ocr)/len(colorful_char_ocr):.3f}", f" total imgs:{len(colorful_char_ocr)/400}")
437
+ print("pure_words_ocr word-level accuracy: ", f"{sum(pure_words_ocr) / len(pure_words_ocr):.3f}", f" total imgs:{len(pure_words_ocr)/400}")
438
+ print("colorful_words_ocr word-level accuracy: ", f"{sum(colorful_words_ocr) / len(colorful_words_ocr):.3f}", f" total imgs:{len(colorful_words_ocr)/400}")
439
+
440
+ def task_font_size(data):
441
+ """ font size robustness """
442
+ font_size_list = [80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15]
443
+ font_size_dic = {}
444
+ font_size_dic2 = {}
445
+ for size in font_size_list:
446
+ result1 = []
447
+ for item in data:
448
+ if item["task"] == "font size ocr":
449
+ if size == item["subtask"]:
450
+ gt = item["gt"]
451
+ response = item["response"]
452
+ # if word_level_ac(gt, response)<0.1:
453
+ # continue
454
+
455
+ result1.append(word_level_ac(gt, response))
456
+ font_size_dic[str(size)] = sum(result1)/len(result1)
457
+ font_size_dic2[str(size)] = len(result1)
458
+
459
+ # print(f"font size robustness:")
460
+ # for size in font_size_list:
461
+ # print(f"font size {size} : {font_size_dic[str(size)]:5f} total imgs: {font_size_dic2[str(size)]}")
462
+
463
+ font_size_dic3 = {}
464
+ font_size_dic4 = {}
465
+ for size in font_size_list:
466
+ result2 = []
467
+ for item in data:
468
+ if item["task"] == "font size ocr":
469
+ if size == item["subtask"]:
470
+ gt = item["gt"]
471
+ response = item["response"]
472
+ if word_level_ac(gt, response)<0.1:
473
+ continue
474
+
475
+ result2.append(word_level_ac(gt, response))
476
+ font_size_dic3[str(size)] = sum(result2)/len(result2)
477
+ font_size_dic4[str(size)] = len(result2)
478
+
479
+ # print(f"font size robustness:")
480
+ # for size in font_size_list:
481
+ # print(f"font size {size} : {font_size_dic3[str(size)]:5f} total imgs: {font_size_dic4[str(size)]}")
482
+
483
+ values = list(font_size_dic.values())
484
+ mean = statistics.mean(values)
485
+ std = statistics.stdev(values) # 样本标准差(ddof=1)
486
+
487
+ values3 = list(font_size_dic3.values())
488
+ mean3 = statistics.mean(values3)
489
+ std3 = statistics.stdev(values3)
490
+
491
+ recall_num = list(font_size_dic4.values())
492
+ mean_r = statistics.mean(recall_num)
493
+
494
+ # print(f"Mean: {mean:.3f} Std: {std:.3f} Mean: {mean3:.3f} Std: {std3:.3f} reacall_num: {mean_r}")
495
+ print(f"Mean: {mean:.3f} Std: {std:.3f} Mean: {mean3:.3f} Std: {std3:.3f} reacall_num: {mean_r:.3f}")
496
+
497
+ def task_logo_cor(data):
498
+ """ logo ocr """
499
+ result = []
500
+ for item in data:
501
+ if item["task"] == "logo ocr":
502
+ gt = item["gt"]
503
+ response = item["response"]
504
+ result.append(logo_ocr_ac(gt, response))
505
+ print(f"logo ocr accuracy: {sum(result)/len(result):.3f} total imgs: {len(result)}")
506
+
507
+ def task_poster_ocr(data):
508
+ """ real poster ocr """
509
+ result = []
510
+ for item in data:
511
+ if item["task"] == "poster ocr":
512
+ if "gt" in item:
513
+ gt = item["gt"]
514
+ if "texts" in item:
515
+ gt = item["texts"]
516
+ response = item["response"]
517
+ ac = real_poster_ac(gt, response)
518
+ if ac<0.05: continue
519
+ result.append(ac)
520
+ print(f"poster ocr accuracy (entity-level): {sum(result)/len(result):.3f} total imgs: {len(result)}")
521
+
522
+ def task_font_matching_1(data):
523
+ """ font matching 1 """
524
+ result = []
525
+ for item in data:
526
+ if item["task"] == "font matching 1":
527
+ if "gt" in item:
528
+ gt = item["gt"]
529
+ if "texts" in item:
530
+ gt = item["texts"]
531
+ response = item["response"]
532
+ if refuse_option(response):
533
+ continue
534
+ # print(response)
535
+ result.append(font_matching_ac(gt, response))
536
+ print(f"font matching 1 accuracy: {sum(result) / len(result):5f} total imgs: {len(result)}")
537
+ return sum(result) / len(result)
538
+
539
+ def task_font_matching_2(data):
540
+ """ font matching 2 """
541
+ result = []
542
+ for item in data:
543
+ if item["task"] == "font matching 2":
544
+ if "gt" in item:
545
+ gt = item["gt"]
546
+ if "texts" in item:
547
+ gt = item["texts"]
548
+ response = item["response"]
549
+ if refuse_option(response):
550
+ continue
551
+ # print(response)
552
+ result.append(font_matching_ac(gt, response))
553
+ print(f"font matching 2 accuracy: {sum(result) / len(result):5f} total imgs: {len(result)}")
554
+ return sum(result) / len(result)
555
+
556
+ def task_font_matching(data):
557
+ """ font matching 2 """
558
+ result = []
559
+ for item in data:
560
+ if item["task"] == "font matching 2" or item["task"] == "font matching 1":
561
+ if "gt" in item:
562
+ gt = item["gt"]
563
+ if "texts" in item:
564
+ gt = item["texts"]
565
+ response = item["response"]
566
+ if refuse_option(response):
567
+ continue
568
+ # print(response)
569
+ result.append(font_matching_ac(gt, response))
570
+ print(f"font matching 2 accuracy: {sum(result) / len(result):.3f} total imgs: {len(result)}")
571
+ return sum(result) / len(result)
572
+
573
+ def task_font_attr(data):
574
+ """ font attributes """
575
+ result = []
576
+ for item in data:
577
+ if item["task"] == "font attributes":
578
+ if "gt" in item:
579
+ gt = item["gt"]
580
+ if "texts" in item:
581
+ gt = item["texts"]
582
+ response = item["response"]
583
+ if refuse_option(response):
584
+ continue
585
+ # print(response)
586
+ result.append(font_attr_ac(gt, response))
587
+ print(f"font attributes accuracy: {sum(result) / len(result):5f} total imgs: {len(result)}")
588
+
589
+ font_attr_list = []
590
+ font_attr_dic = {}
591
+ for item in data:
592
+ if item["task"] == "font attributes":
593
+ font_attr_list.append(item["subtask"])
594
+ font_attr_list = list(set(font_attr_list))
595
+ # print(font_attr_list)
596
+ for attr in font_attr_list:
597
+ result2 = []
598
+ for item in data:
599
+ if item["task"] == "font attributes":
600
+ if item["subtask"] == attr:
601
+ if "gt" in item:
602
+ gt = item["gt"]
603
+ if "texts" in item:
604
+ gt = item["texts"]
605
+ response = item["response"]
606
+ result2.append(font_attr_ac(gt, response))
607
+ font_attr_dic[attr]= sum(result2) / len(result2)
608
+
609
+ # for attr in font_attr_list:
610
+ # print(f"attr {attr}: {font_attr_dic[attr]:5f}")
611
+ return sum(result) / len(result)
612
+
613
+ def task_font_effect(data):
614
+ """ font effect """
615
+ result = []
616
+ for item in data:
617
+ if item["task"] == "font effect":
618
+ if "gt" in item:
619
+ gt = item["gt"]
620
+ if "texts" in item:
621
+ gt = item["texts"]
622
+ response = item["response"]
623
+ # print(response)
624
+ result.append(font_effect_ac(gt, response))
625
+ print(f"font effect accuracy: {sum(result) / len(result):.5f} total imgs: {len(result)}")
626
+
627
+ font_effect_list = []
628
+ font_effect_dic = {}
629
+ for item in data:
630
+ if item["task"] == "font effect":
631
+ font_effect_list.append(item["subtask"])
632
+ font_effect_list = list(set(font_effect_list))
633
+ # print(font_effect_list)
634
+
635
+ for effect in font_effect_list:
636
+ result2 = []
637
+ for item in data:
638
+ if item["task"] == "font effect":
639
+ if item["subtask"] == effect:
640
+ if "gt" in item:
641
+ gt = item["gt"]
642
+ response = item["response"]
643
+ result2.append(font_effect_ac(gt, response))
644
+ font_effect_dic[effect] = sum(result2) / len(result2)
645
+ # for effect in font_effect_list:
646
+ # print(f"attr {effect}: {font_effect_dic[effect]:5f}")
647
+
648
+ return sum(result) / len(result)
649
+
650
+ def task_font_effect_2(data):
651
+ """ font effect 2 """
652
+ result_c = []
653
+ result_e = []
654
+ for item in data:
655
+ if item["task"] == "font effect 2":
656
+ if "gt" in item:
657
+ gt = item["gt"]
658
+ if "texts" in item:
659
+ gt = item["texts"]
660
+ response = item["response"]
661
+ # print(response)
662
+ color_ac, effect_ac = font_effect_2_ac(gt, response)
663
+ result_c.append(color_ac)
664
+ if effect_ac != None:
665
+ result_e.append(effect_ac)
666
+
667
+ print(f"font effect 2 color accuracy: {sum(result_c) / len(result_c):5f} total imgs: {len(result_c)}")
668
+ print(f"font effect 2 effect accuracy: {sum(result_e) / len(result_e):5f} total imgs: {len(result_e)}")
669
+
670
+ return sum(result_c) / len(result_c), sum(result_e) / len(result_e)
671
+
672
+ def task_layout_comprison(data):
673
+ """ layout comprison """
674
+ result = []
675
+ for item in data:
676
+ if item["task"] == "layout comparison":
677
+ if "gt" in item:
678
+ gt = item["gt"]
679
+ if "texts" in item:
680
+ gt = item["texts"]
681
+ response = item["response"]
682
+ # print(response)
683
+ result.append(font_effect_ac(gt, response))
684
+ print(f"layout disorder comparison accuracy: {sum(result) / len(result):5f} total imgs: {len(result)}")
685
+ return sum(result) / len(result)
686
+
687
+
688
+ def task_align_rotate(data):
689
+ """ layout comprison """
690
+ a_result = []
691
+ r_result = []
692
+ r1_result = []
693
+ r2_result = []
694
+ r3_result = []
695
+
696
+ for item in data:
697
+ response = item["response"]
698
+ if isinstance(response, list):
699
+ answer = ""
700
+ for content in response:
701
+ answer += content
702
+ if isinstance(response, str):
703
+ answer = response
704
+
705
+ if item["task"] == "align and rotate":
706
+ if "gt" in item:
707
+ gt = item["gt"]
708
+ if "alignment" in item:
709
+ gt_align = item["alignment"]
710
+ if "rotation" in item:
711
+ gt_rotate = item["rotation"]
712
+
713
+ r_ac = 0
714
+ if "counterclockwise rotation" in gt_rotate:
715
+ if "counterclockwise rotation" in answer:
716
+ r1_ac = 1
717
+ else:
718
+ r1_ac = 0
719
+ r1_result.append(r1_ac)
720
+ if "no rotation" in gt_rotate:
721
+ if "no rotation" in answer:
722
+ r2_ac = 1
723
+ else:
724
+ r2_ac = 0
725
+ r2_result.append(r2_ac)
726
+
727
+ if "clockwise rotation" in gt_rotate:
728
+ if "counterclockwise rotation" in answer:
729
+ r3_ac = 0
730
+ elif "clockwise rotation" in answer:
731
+ r3_ac = 1
732
+ else:
733
+ r3_ac = 0
734
+ r3_result.append(r3_ac)
735
+
736
+ for a in gt_align:
737
+ a_ac = 0
738
+ if a in answer:
739
+ a_ac = 1
740
+ a_result.append(a_ac)
741
+
742
+
743
+ r_result.extend(r1_result)
744
+ r_result.extend(r2_result)
745
+ r_result.extend(r3_result)
746
+
747
+
748
+ print(f"alignment accuracy: {sum(a_result) / len(a_result):5f} total imgs: {len(a_result)}")
749
+ print(f"rotation accuracy: {sum(r1_result) / len(r1_result):5f} total imgs: {len(r1_result)}")
750
+ print(f"rotation accuracy: {sum(r2_result) / len(r2_result):5f} total imgs: {len(r2_result)}")
751
+ print(f"rotation accuracy: {sum(r3_result) / len(r3_result):5f} total imgs: {len(r3_result)}")
752
+
753
+ return sum(a_result) / len(a_result), sum(r_result) / len(r_result)
754
+
755
+
756
+
757
+ def task_poster_detection(data, max_box_num=30):
758
+ """ poster detection """
759
+ ratio_list = []
760
+ wrong_recall = 0
761
+ iou_list = []
762
+ center_bias_list = []
763
+ area_ratio_list = []
764
+ for item in data:
765
+ if item["task"] == "poster detection":
766
+ if "gt" in item:
767
+ gt_bboxs = item["gt"]
768
+ if "text_bbox" in item:
769
+ gt_bboxs = item["text_bbox"]
770
+ width, height = item["size"]
771
+ response = item["response"]
772
+ if isinstance(response, list):
773
+ answer = ""
774
+ for content in response:
775
+ answer += content
776
+ if isinstance(response, str):
777
+ answer = response
778
+
779
+
780
+ pre_bboxs = parse_bbox_string2(answer)
781
+ # new_item["text_bbox"] = pre_bboxs
782
+ # new_item["text_bbox"] = [denorm_bbox(pre_bboxs[i], [width, height]) for i in range(len(pre_bboxs))]
783
+ bbox_type = bbox_number_types(pre_bboxs)
784
+
785
+ ratio = min(len(pre_bboxs) / len(gt_bboxs) , 1)
786
+ ratio_list.append(ratio)
787
+ if ratio != 1:
788
+ # print(f"{ratio:3f} boxes: {len(gt_bboxs)}")
789
+ wrong_recall += 1
790
+ # else:
791
+ """最多算5个bbox"""
792
+ incount_bbox_num = min(len(gt_bboxs), len(pre_bboxs), max_box_num)
793
+ for i in range(incount_bbox_num):
794
+ # print(pre_bboxs[i])
795
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))>1:
796
+ """calculate iou"""
797
+ iou1 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [width, height]))
798
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))<1:
799
+ iou2 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), pre_bboxs[i])
800
+
801
+ iou3 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1024, 1024]))
802
+
803
+ iou4 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1000, 1000]))
804
+
805
+ ious = [iou1, iou2, iou3, iou4]
806
+ max_iou = max(ious)
807
+ max_index = ious.index(max_iou)
808
+
809
+ """calculate center distance"""
810
+ dis1 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [width, height]))
811
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))<1:
812
+ dis2 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), pre_bboxs[i])
813
+
814
+ dis3 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1024, 1024]))
815
+
816
+ dis4 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1000, 1000]))
817
+
818
+ dis_list = [dis1, dis2, dis3, dis4]
819
+ min_center_dis = min(dis_list)
820
+ index = dis_list.index(min_center_dis)
821
+
822
+ """calculate area ratio"""
823
+ area_r_1 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [width, height]))
824
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))<1:
825
+ area_r_2 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), pre_bboxs[i])
826
+
827
+ area_r_3 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1024, 1024]))
828
+
829
+ area_r_4 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1000, 1000]))
830
+
831
+ area_r_t = [abs(area_r_1 - 1 ), abs(area_r_2 - 1 ), abs(area_r_3 - 1 ), abs(area_r_4 - 1 )]
832
+ area_r_s = [area_r_1, area_r_2, area_r_3, area_r_4]
833
+ value = min(area_r_t)
834
+ index = area_r_t.index(value)
835
+ area_r = area_r_s[index]
836
+ # print("area_r",area_r)
837
+
838
+
839
+ iou_list.append(max_iou)
840
+ center_bias_list.append(min_center_dis)
841
+ area_ratio_list.append(area_r)
842
+
843
+ # print("wrong recall rate:", wrong_recall / len(ratio_list))
844
+ # print(f"ratio mean: {sum(ratio_list)/len(ratio_list)} ration vat: {statistics.pstdev(ratio_list)} ")
845
+ # print("box total: ",len(iou_list))
846
+ # print(f"iou mean: {sum(iou_list) / len(iou_list):5f}")
847
+ # print(f"iou pstdev: {statistics.pstdev(iou_list):5f}")
848
+ #
849
+ # print(f"center shift mean : {sum(center_bias_list) / len(center_bias_list):5f}")
850
+ # print(f"center shift pstdev: {statistics.pstdev(center_bias_list):5f}")
851
+ #
852
+ # print(f"area_ratio mean: {sum(area_ratio_list) / len(area_ratio_list):5f}")
853
+ # print(f"area_ratio pstdev: {statistics.pstdev(area_ratio_list):5f}")
854
+ return sum(iou_list) / len(iou_list), sum(ratio_list)/len(ratio_list)
855
+
856
+ def task_layout_generation(data):
857
+ """ poster detection """
858
+ ratio_list = []
859
+ wrong_recall = 0
860
+ iou_list = []
861
+ center_bias_list = []
862
+ area_ratio_list = []
863
+ for item in data:
864
+ if item["task"] == "layout generation":
865
+ if "gt" in item:
866
+ gt_bboxs = item["gt"]
867
+ if "text_bbox" in item:
868
+ gt_bboxs = item["text_bbox"]
869
+ width, height = item["size"]
870
+ response = item["response"]
871
+ if isinstance(response, list):
872
+ answer = ""
873
+ for content in response:
874
+ answer += content
875
+ if isinstance(response, str):
876
+ answer = response
877
+
878
+
879
+ pre_bboxs = parse_bbox_string2(answer)
880
+ # new_item["text_bbox"] = pre_bboxs
881
+ # new_item["text_bbox"] = [denorm_bbox(pre_bboxs[i], [width, height]) for i in range(len(pre_bboxs))]
882
+ bbox_type = bbox_number_types(pre_bboxs)
883
+
884
+ ratio = min(len(pre_bboxs) / len(gt_bboxs), 1)
885
+ # ratio = len(pre_bboxs) / len(gt_bboxs)
886
+ ratio_list.append(ratio)
887
+ if ratio != 1:
888
+ # print(f"{ratio:3f} boxes: {len(gt_bboxs)}")
889
+ wrong_recall += 1
890
+ # else:
891
+ """最多算5个bbox"""
892
+ incount_bbox_num = min(len(gt_bboxs), len(pre_bboxs))
893
+ for i in range(incount_bbox_num):
894
+ # print(pre_bboxs[i])
895
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))>1:
896
+ """calculate iou"""
897
+ iou1 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [width, height]))
898
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))<1:
899
+ iou2 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), pre_bboxs[i])
900
+
901
+ iou3 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1024, 1024]))
902
+
903
+ iou4 = calculate_iou(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1000, 1000]))
904
+
905
+ ious = [iou1, iou2, iou3, iou4]
906
+ max_iou = max(ious)
907
+ max_index = ious.index(max_iou)
908
+
909
+ """calculate center distance"""
910
+ dis1 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [width, height]))
911
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))<1:
912
+ dis2 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), pre_bboxs[i])
913
+
914
+ dis3 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1024, 1024]))
915
+
916
+ dis4 = calculate_centerpoint(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1000, 1000]))
917
+
918
+ dis_list = [dis1, dis2, dis3, dis4]
919
+ min_center_dis = min(dis_list)
920
+ index = dis_list.index(min_center_dis)
921
+
922
+ """calculate area ratio"""
923
+ area_r_1 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [width, height]))
924
+ # if (sum(pre_bboxs[i])/len(pre_bboxs[i]))<1:
925
+ area_r_2 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), pre_bboxs[i])
926
+
927
+ area_r_3 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1024, 1024]))
928
+
929
+ area_r_4 = calculate_area_ratio(norm_bbox(gt_bboxs[i], [width, height]), norm_bbox(pre_bboxs[i], [1000, 1000]))
930
+
931
+ area_r_t = [abs(area_r_1 - 1 ), abs(area_r_2 - 1 ), abs(area_r_3 - 1 ), abs(area_r_4 - 1 )]
932
+ area_r_s = [area_r_1, area_r_2, area_r_3, area_r_4]
933
+ value = min(area_r_t)
934
+ index = area_r_t.index(value)
935
+ area_r = area_r_s[index]
936
+ if area_r >1 :
937
+ area_r = 1/area_r
938
+ # print("area_r",area_r)
939
+
940
+
941
+ iou_list.append(max_iou)
942
+ center_bias_list.append(min_center_dis)
943
+ area_ratio_list.append(area_r)
944
+
945
+ # print("wrong recall rate:", wrong_recall / len(ratio_list))
946
+ # print(f"ratio mean: {sum(ratio_list)/len(ratio_list):.3f} ration vat: {statistics.pstdev(ratio_list):.3f} ")
947
+ rate = sum(ratio_list)/len(ratio_list)
948
+ # print("box total: ",len(iou_list))
949
+ # print(f"iou mean: {sum(iou_list) / len(iou_list):.3f}")
950
+ # print(f"iou pstdev: {statistics.pstdev(iou_list):5f}")
951
+
952
+ # print(f"center shift mean : {sum(center_bias_list) / len(center_bias_list):.3f}")
953
+ bias = sum(center_bias_list) / len(center_bias_list)
954
+ # print(f"center shift pstdev: {statistics.pstdev(center_bias_list):.3f}")
955
+
956
+ # print(f"area_ratio mean: {sum(area_ratio_list) / len(area_ratio_list):.3f}")
957
+ area_rate = sum(area_ratio_list) / len(area_ratio_list)
958
+ # print(f"area_ratio pstdev: {statistics.pstdev(area_ratio_list):.3f}")
959
+
960
+ return bias, area_rate, rate
961
+
962
+ def extract_last_bracket_list(s: str) -> list:
963
+ """
964
+ 在字符串中定位最后一个 '[' 和最后一个 ']',并将它们之间的内容提取、
965
+ 按逗号拆分后返回为 Python 列表。
966
+
967
+ Args:
968
+ s (str): 输入字符串
969
+
970
+ Returns:
971
+ list: 拆分后的元素列表(去除两端空白),如果未找到匹配的括号,则返回空列表
972
+ """
973
+ # 查找最后一个 '[' 和最后一个 ']'
974
+ last_open = s.rfind('[')
975
+ last_close = s.rfind(']')
976
+
977
+ # 如果任意一个不存在,或顺序不对,则返回空列表
978
+ if last_open == -1 or last_close == -1 or last_open > last_close:
979
+ return []
980
+
981
+ # 提取中间的子串
982
+ content = s[last_open + 1:last_close]
983
+
984
+ # 按逗号分割,并去除每个元素的首尾空白
985
+ # 如果希望支持空元素,也可以改用 content.split(',')
986
+ items = [int(item.strip()) for item in content.split(',') if item.strip()]
987
+
988
+ return items
989
+
990
+ def list_iou(list1, list2):
991
+ """
992
+ 计算两个列表(或任何可迭代对象)中元素的交并比(IoU)。
993
+
994
+ Args:
995
+ list1 (list): 第一个列表
996
+ list2 (list): 第二个列表
997
+
998
+ Returns:
999
+ float: IoU 值,范围 [0, 1]。如果二者都为空,则返回 1.0。
1000
+ """
1001
+ set1 = set(list1)
1002
+ set2 = set(list2)
1003
+
1004
+ if not set1 and not set2:
1005
+ return 1.0 # 两个都为空,定义 IoU 为 1
1006
+
1007
+ intersection = set1 & set2
1008
+ union = set1 | set2
1009
+
1010
+ iou = len(intersection) / len(union)
1011
+ return iou
1012
+
1013
+ def task_empty_space(data):
1014
+ """ layout comprison """
1015
+ result = []
1016
+ wrong_recall_list = []
1017
+ for item in data:
1018
+ if item["task"] == "empty space":
1019
+ if "gt" in item:
1020
+ gt = item["gt"]
1021
+ response = item["response"]
1022
+ if isinstance(response, list):
1023
+ answer = ""
1024
+ for content in response:
1025
+ answer += content
1026
+ if isinstance(response, str):
1027
+ answer = response
1028
+
1029
+ answer = extract_last_bracket_list(answer)
1030
+ ac = list_iou(gt, answer)
1031
+ # print(ac)
1032
+ result.append(ac)
1033
+ if len(gt)==len(answer):
1034
+ wrong_recall = 1
1035
+ else:
1036
+ wrong_recall = 0
1037
+ wrong_recall_list.append(wrong_recall)
1038
+
1039
+ # print(f"empty space accuracy: {sum(result) / len(result):.5f} total imgs: {len(result)}")
1040
+ # print(f"empty space recall : {sum(wrong_recall_list) / len(wrong_recall_list):.5f} total imgs: {len(wrong_recall_list)}")
1041
+
1042
+ return sum(result) / len(result) , sum(wrong_recall_list)/len(wrong_recall_list)
1043
+
1044
+
1045
+ def k_option_norm(rate, k):
1046
+
1047
+ grade = ((k*rate) - 1) / (k - 1)
1048
+
1049
+ return grade
1050
+
1051
+ def refuse_option(text):
1052
+ if isinstance(text, list):
1053
+ response = ""
1054
+ for item in text:
1055
+ response += clean_string(item)
1056
+ if isinstance(text, str):
1057
+ response = clean_string(text)
1058
+ gt_list = ["A","B","C","D","E","F","G","H","I"]
1059
+ """ situation 1 No letter there"""
1060
+ none_flag = False
1061
+ for item in gt_list:
1062
+ if item in response:
1063
+ none_flag = True
1064
+ if none_flag==False: return True
1065
+
1066
+ """ situation 2 """
1067
+ if len(response)>5:
1068
+ count = 0
1069
+ num = 0
1070
+ for item in gt_list:
1071
+ count = max(response.count(item), count)
1072
+ if response.count(item):
1073
+ num += 1
1074
+ if (count<=1)&(num>1):
1075
+ return True
1076
+
1077
+
1078
+ def task_ads(data):
1079
+
1080
+ score_list = []
1081
+ points = 0
1082
+ for item in data:
1083
+ if item["task"]=="advertisement reasoning":
1084
+ item_point_list = []
1085
+ if "judge" in item:
1086
+
1087
+ for content in item["judge"]:
1088
+ if "Yes" in content:
1089
+ points += 1
1090
+ item_point_list.append(1)
1091
+ else:
1092
+ item_point_list.append(0)
1093
+ score = sum(item_point_list)/len(item_point_list)
1094
+ score_list.append(score)
1095
+
1096
+ # print(f"{sum(score_list)/len(score_list):.3f} {points} ")
1097
+ print(f"{sum(score_list) / len(score_list):.3f}")
1098
+
1099
+
1100
+ if __name__=="__main__":
1101
+
1102
+ # # data = read_json_file(r"Llama-3.2-11B-Vision-Instruct_bench.json")
1103
+ # task_4_ocr(data)
1104
+ # task_logo_cor(data)
1105
+ # task_poster_ocr(data)
1106
+ # task_font_matching_1(data)
1107
+ # task_font_matching_2(data)
1108
+ # task_font_attr(data)
1109
+ # task_font_effect(data)
1110
+ # task_font_effect_2(data)
1111
+ # task_font_size(data)
1112
+ # task_layout_comprison(data)
1113
+ # task_poster_detection(data)
1114
+ # task_layout_generation(data)
1115
+ # task_align_rotate(data)
1116
+ # task_empty_space(data)
1117
+ jsonlist = [
1118
+ ]
1119
+ for json_item in jsonlist:
1120
+ print(os.path.basename(json_item))
1121
+ data = read_json_file(json_item)
1122
+ top1_iou, _ = task_poster_detection(data, max_box_num=1)
1123
+ top3_iou, _ = task_poster_detection(data, max_box_num=3)
1124
+ top5_iou, _ = task_poster_detection(data, max_box_num=5)
1125
+ mean_iou, recall = task_poster_detection(data, max_box_num=30)
1126
+ print(f"{top1_iou:.3f} & {top3_iou:.3f} & {top5_iou:.3f} & {mean_iou:.3f} & {recall:.3f}")
1127
+
1128
+ #
1129
+ # bias, area_rate, rate = task_layout_generation(data)
1130
+ # print(f"{bias:.3f} & {area_rate:.3f} & {rate:.3f}")