stat.py 1.53 KB
Newer Older
1
#!/usr/bin/env python
congee's avatar
congee committed
2
import functools as func
3
import glob
congee's avatar
congee committed
4
import numpy as np
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re
from os import path as osp

url_prefix = 'https://github.com/open-mmlab/mmdetection3d/blob/master/'

files = sorted(glob.glob('../configs/*/README.md'))

stats = []
titles = []
num_ckpts = 0

for f in files:
    url = osp.dirname(f.replace('../', url_prefix))

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

congee's avatar
congee committed
22
    title = content.split('\n')[0].replace('#', '').strip()
23
24
25
    ckpts = set(x.lower().strip()
                for x in re.findall(r'https?://download.*\.pth', content)
                if 'mmdetection3d' in x)
congee's avatar
congee committed
26
27
28
    if len(ckpts) == 0:
        continue

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

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

congee's avatar
congee committed
35
    titles.append(title)
36
37
    num_ckpts += len(ckpts)
    statsmsg = f"""
congee's avatar
congee committed
38
\t* [{papertype}] [{title}]({url}) ({len(ckpts)} ckpts)
39
"""
congee's avatar
congee committed
40
    stats.append((paper, ckpts, statsmsg))
41

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

congee's avatar
congee committed
45
46
47
48
49
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)])

50
51
52
modelzoo = f"""
\n## Model Zoo Statistics

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

56
57
58
59
60
61
* Number of checkpoints: {num_ckpts}
{msglist}
"""

with open('model_zoo.md', 'a') as f:
    f.write(modelzoo)