stat.py 1.49 KB
Newer Older
1
#!/usr/bin/env python
congee's avatar
congee committed
2
import functools as func
3
4
5
6
import glob
import re
from os import path as osp

7
8
import numpy as np

9
url_prefix = 'https://github.com/open-mmlab/mmdetection3d/blob/main/'
10

Xiang Xu's avatar
Xiang Xu committed
11
files = sorted(glob.glob('../../configs/*/README.md'))
12
13
14
15
16
17

stats = []
titles = []
num_ckpts = 0

for f in files:
Xiang Xu's avatar
Xiang Xu committed
18
    url = osp.dirname(f.replace('../../', url_prefix))
19
20
21
22

    with open(f, 'r') as content_file:
        content = content_file.read()

Xiang Xu's avatar
Xiang Xu committed
23
    title = content.split('\n')[0].replace('# ', '').strip()
24
    ckpts = set(x.lower().strip()
Xiang Xu's avatar
Xiang Xu committed
25
26
                for x in re.findall(r'\[model\]\((https?.*)\)', content))

congee's avatar
congee committed
27
28
29
    if len(ckpts) == 0:
        continue

Xiang Xu's avatar
Xiang Xu committed
30
    _papertype = [x for x in re.findall(r'\[([A-Z]+)\]', content)]
congee's avatar
congee committed
31
32
33
34
35
    assert len(_papertype) > 0
    papertype = _papertype[0]

    paper = set([(papertype, title)])

congee's avatar
congee committed
36
    titles.append(title)
37
    num_ckpts += len(ckpts)
Xiang Xu's avatar
Xiang Xu committed
38

39
    statsmsg = f"""
congee's avatar
congee committed
40
\t* [{papertype}] [{title}]({url}) ({len(ckpts)} ckpts)
41
"""
congee's avatar
congee committed
42
    stats.append((paper, ckpts, statsmsg))
43

congee's avatar
congee committed
44
allpapers = func.reduce(lambda a, b: a.union(b), [p for p, _, _ in stats])
45
46
msglist = '\n'.join(x for _, _, x in stats)

congee's avatar
congee committed
47
48
49
50
51
papertypes, papercounts = np.unique([t for t, _ in allpapers],
                                    return_counts=True)
countstr = '\n'.join(
    [f'   - {t}: {c}' for t, c in zip(papertypes, papercounts)])

52
modelzoo = f"""
Xiang Xu's avatar
Xiang Xu committed
53
# Model Zoo Statistics
54

congee's avatar
congee committed
55
* Number of papers: {len(set(titles))}
congee's avatar
congee committed
56
57
{countstr}

58
* Number of checkpoints: {num_ckpts}
Xiang Xu's avatar
Xiang Xu committed
59

60
61
62
{msglist}
"""

Xiang Xu's avatar
Xiang Xu committed
63
with open('modelzoo_statistics.md', 'w') as f:
64
    f.write(modelzoo)