File size: 10,287 Bytes
243897a 8e5bfdb 243897a 5ab1442 243897a 62c094e 243897a 62c094e 243897a 0d67165 feba5dc 0d67165 243897a 5ab1442 62c094e 5ab1442 243897a 5ab1442 243897a 5ab1442 243897a 5ab1442 243897a 5ab1442 0d67165 243897a 5ab1442 243897a 5ab1442 243897a |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
import json
import pandas as pd
from collections import defaultdict
import gradio as gr
import copy as cp
import numpy as np
def listinstr(lst, s):
assert isinstance(lst, list)
for item in lst:
if item in s:
return True
return False
# CONSTANTS-URL
# RESULT_FILE = '../video_leaderboard.json'
URL = "http://opencompass.openxlab.space/utils/video_leaderboard.json"
VLMEVALKIT_README = 'https://raw.githubusercontent.com/open-compass/VLMEvalKit/main/README.md'
# CONSTANTS-CITATION
CITATION_BUTTON_TEXT = r"""@misc{duan2024vlmevalkitopensourcetoolkitevaluating,
title={VLMEvalKit: An Open-Source Toolkit for Evaluating Large Multi-Modality Models},
author={Haodong Duan and Junming Yang and Yuxuan Qiao and Xinyu Fang and Lin Chen and Yuan Liu and Amit Agarwal and Zhe Chen and Mo Li and Yubo Ma and Hailong Sun and Xiangyu Zhao and Junbo Cui and Xiaoyi Dong and Yuhang Zang and Pan Zhang and Jiaqi Wang and Dahua Lin and Kai Chen},
year={2024},
eprint={2407.11691},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2407.11691},
}"""
CITATION_BUTTON_LABEL = "Copy the following snippet to cite these results"
# CONSTANTS-TEXT
LEADERBORAD_INTRODUCTION = """# OpenVLM Video Leaderboard
### Welcome to the OpenVLM Video Leaderboard! On this leaderboard we share the evaluation results of VLMs on the video understanding benchmark obtained by the OpenSource Framework [**VLMEvalKit**](https://github.com/open-compass/VLMEvalKit) 🏆
### Currently, OpenVLM Video Leaderboard covers {} different VLMs (including GPT-4o, Gemini-1.5, LLaVA-OneVision, etc.) and {} different video understanding benchmarks.
This leaderboard was last updated: {}.
"""
# CONSTANTS-FIELDS
META_FIELDS = ['Method', 'Parameters (B)', 'Language Model', 'Vision Model', 'OpenSource', 'Verified', 'Frames']
MAIN_FIELDS = ['MVBench', 'Video-MME (w/o subs)', 'MMBench-Video', 'TempCompass', 'MLVU']
MODEL_SIZE = ['<10B', '10B-20B', '20B-40B', '>40B', 'Unknown']
MODEL_TYPE = ['API', 'OpenSource']
# The README file for each benchmark
LEADERBOARD_MD = {}
LEADERBOARD_MD['MAIN'] = """
## Main Evaluation Results
- Avg Score: The average score on all video understanding Benchmarks (normalized to 0 - 100, the higher the better).
- Avg Rank: The average rank on all video understanding Benchmarks (the lower the better).
- The overall evaluation results on 5 video understanding benchmarks, sorted by the ascending order of Avg Rank.
- Tip: The total score of MLVU is calculated as a weighted sum of M-Avg and G-Avg, with weights based on the proportion of the number of questions in each category relative to the total. The maximum possible score is 100.
"""
LEADERBOARD_MD['Video-MME (w/o subs)'] = """
## Video-MME (w/o subs) Evaluation Results
- We give the total scores for the three video lengths (short, medium and long), as well as the total scores for each task type.
"""
LEADERBOARD_MD['MLVU'] = """
## MLVU Evaluation Results
- The ranking here is determined by sorting the M-Avg scores in descending order.
- The number of evaluation questions used here is consistent with the official Hugging Face benchmark.
"""
# LEADERBOARD_MD['MVBench'] = """
# ## MVBench Evaluation Results
# """
# LEADERBOARD_MD['MMBench-Video'] = """
# ## MMBench-Video Evaluation Results
# """
from urllib.request import urlopen
# def load_results():
# with open(RESULT_FILE, 'r', encoding='utf-8') as file:
# data = json.load(file)
# return data
def load_results():
data = json.loads(urlopen(URL).read())
return data
def nth_large(val, vals):
return sum([1 for v in vals if v > val]) + 1
def format_timestamp(timestamp):
return timestamp[:2] + '.' + timestamp[2:4] + '.' + timestamp[4:6] + ' ' + timestamp[6:8] + ':' + timestamp[8:10] + ':' + timestamp[10:12]
def model_size_flag(sz, FIELDS):
if pd.isna(sz) or sz == 'N/A':
if 'Unknown' in FIELDS:
return True
else:
return False
sz = float(sz.replace('B','').replace('(LLM)',''))
if '<10B' in FIELDS and sz < 10:
return True
if '10B-20B' in FIELDS and sz >= 10 and sz < 20:
return True
if '20B-40B' in FIELDS and sz >= 20 and sz < 40:
return True
if '>40B' in FIELDS and sz >= 40:
return True
return False
def model_type_flag(line, FIELDS):
if 'OpenSource' in FIELDS and line['OpenSource'] == 'Yes':
return True
if 'API' in FIELDS and line['OpenSource'] == 'No':
return True
return False
def BUILD_L1_DF(results, fields):
res = defaultdict(list)
for i, m in enumerate(results):
item = results[m]
meta = item['META']
skip_model_in_main = False
for main_dataset in MAIN_FIELDS:
# judge dict is empty
if main_dataset not in item.keys() or item[main_dataset] == {}:
skip_model_in_main = True
break
if skip_model_in_main:
print(f'skip {meta}')
continue
for k in META_FIELDS:
if k == 'Parameters (B)':
param = meta['Parameters']
res[k].append(param.replace('B', '') if param != '' else None)
# res[k].append(float(param.replace('B', '')) if param != '' else None)
elif k == 'Method':
name, url = meta['Method']
res[k].append(f'<a href="{url}">{name}</a>')
else:
res[k].append(meta[k])
scores, ranks = [], []
for d in fields:
# if d == 'MLVU':
# item[d]['Overall'] = item[d]['M-Avg'] * 0.84 + item[d]['G-Avg'] * 10 * 0.16
# elif d == 'TempCompass':
# item[d]['Overall'] = item[d]['overall']
if d == 'MLVU':
# res[d].append(
# f'M-Avg: {item[d]["M-Avg"]}, G-Avg: {item[d]["G-Avg"]}'
# # {
# # 'M-Avg': item[d]['M-Avg'],
# # 'G-Avg': item[d]['G-Avg']
# # }
# )
res[d].append(item[d]['M-Avg'] * 0.84 + item[d]['G-Avg'] * 10 * 0.16)
elif d == 'TempCompass':
res[d].append(item[d]['overall'])
else:
res[d].append(item[d]['Overall'])
if d == 'MMBench-Video':
scores.append(item[d]['Overall'] / 3 * 100)
elif d == 'TempCompass':
scores.append(item[d]['overall'])
elif d == 'MLVU':
scores.append(item[d]['M-Avg'] * 0.84 + item[d]['G-Avg'] * 10 * 0.16)
else:
scores.append(item[d]['Overall'])
if d == 'MLVU':
ranks.append(nth_large(
item[d]['M-Avg'] * 0.84 + item[d]['G-Avg'] * 10 * 0.16,
[x[d]['M-Avg'] * 0.84 + x[d]['G-Avg'] * 10 * 0.16 for x in results.values() if d in x and 'M-Avg' in x[d] and 'G-Avg' in x[d]]
))
elif d == 'TempCompass':
ranks.append(nth_large(item[d]['overall'], [x[d]['overall'] for x in results.values() if d in x and 'overall' in x[d]]))
else:
ranks.append(nth_large(item[d]['Overall'], [x[d]['Overall'] for x in results.values() if d in x and 'Overall' in x[d]]))
res['Avg Score'].append(round(np.mean(scores), 1))
res['Avg Rank'].append(round(np.mean(ranks), 2))
df = pd.DataFrame(res)
df = df.sort_values('Avg Rank')
check_box = {}
check_box['essential'] = ['Method', 'Parameters (B)', 'Language Model', 'Vision Model', 'Frames']
check_box['required'] = ['Avg Score', 'Avg Rank']
check_box['all'] = check_box['required'] + ['OpenSource', 'Verified'] + fields
type_map = defaultdict(lambda: 'number')
type_map['Method'] = 'html'
type_map['Language Model'] = type_map['Vision Model'] = type_map['OpenSource'] = type_map['Verified'] = type_map['Frames'] = 'str'
check_box['type_map'] = type_map
return df, check_box
def BUILD_L2_DF(results, dataset):
res = defaultdict(list)
fields = list(list(results.values())[0][dataset].keys())
non_overall_fields = [x for x in fields if 'Overall' not in x and 'Avg' not in x and 'overall' not in x]
overall_fields = [x for x in fields if 'Overall' in x or 'Avg' in x or 'overall' in x]
for m in results:
item = results[m]
meta = item['META']
if dataset not in item or item[dataset] == {}:
continue
for k in META_FIELDS:
if k == 'Parameters (B)':
param = meta['Parameters']
res[k].append(param.replace('B', '') if param != '' else None)
# res[k].append(float(param.replace('B', '')) if param != '' else None)
elif k == 'Method':
name, url = meta['Method']
res[k].append(f'<a href="{url}">{name}</a>')
else:
res[k].append(meta[k])
fields = [x for x in fields]
for d in non_overall_fields:
res[d].append(item[dataset][d])
for d in overall_fields:
res[d].append(item[dataset][d])
df = pd.DataFrame(res)
if dataset == 'MLVU':
df = df.sort_values('M-Avg')
elif dataset == 'TempCompass':
df = df.sort_values('overall')
else:
df = df.sort_values('Overall')
df = df.iloc[::-1]
check_box = {}
check_box['essential'] = ['Method', 'Parameters (B)', 'Language Model', 'Vision Model', 'Frames']
if dataset == 'MMBench-Video':
check_box['required'] = overall_fields + ['Perception', 'Reasoning']
elif 'Video-MME' in dataset:
check_box['required'] = overall_fields + ['short', 'medium', 'long']
else:
check_box['required'] = overall_fields
check_box['all'] = non_overall_fields + overall_fields
type_map = defaultdict(lambda: 'number')
type_map['Method'] = 'html'
type_map['Language Model'] = type_map['Vision Model'] = type_map['OpenSource'] = type_map['Verified'] = type_map['Frames'] ='str'
check_box['type_map'] = type_map
# print(check_box, dataset, df.columns)
return df, check_box |