Skip to content

Commit

Permalink
auto modelzoo statistics (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
innerlee authored and wusize committed Nov 13, 2020
1 parent b7ee322 commit 7a1444a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def get_version():

def builder_inited_handler(app):
subprocess.run(['./merge_docs.sh'])
subprocess.run(['./stat.py'])


def setup(app):
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Welcome to MMPose's documentation!
:maxdepth: 2
:caption: Model Zoo

modelzoo.md
top_down_models.md
bottom_up_models.md
hand_models.md
pretrained.md
pretrained_models.md

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion docs/merge_docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
sed -i '$a\\n' ../configs/bottom_up/*/*.md
sed -i '$a\\n' ../configs/top_down/*/*.md
sed -i '$a\\n' ../configs/hand/*/*.md
sed -i '$a\\n' pretrained.md
sed -i '$a\\n' pretrained_models.md

cat ../configs/bottom_up/*/*.md > bottom_up_models.md
cat ../configs/top_down/*/*.md > top_down_models.md
Expand Down
File renamed without changes.
59 changes: 59 additions & 0 deletions docs/stat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
import re
import glob
import functools as func

files = sorted(glob.glob('*_models.md'))

stats = []

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

# title
title = content.split('\n')[0]

# count papers
papers = set(x.lower().strip() for x in re.findall(r'\btitle={(.*)}', content))
paperlist = '\n'.join('* ' + x for x in papers)
if len(papers) > 0:
paperlist = '### Supproted Papers\n\n' + paperlist

# count configs
configs = set(x.lower().strip() for x in re.findall(r'https.*configs/.*\.py', content))

# count ckpts
ckpts = set(x.lower().strip() for x in re.findall(r'https://download.*\.pth', content))

statsmsg = f"""
#{title}
* Number of checkpoints: {len(ckpts)}
* Number of configs: {len(configs)}
* Number of papers: {len(papers)}
{paperlist}
"""

stats.append((papers, configs, ckpts, statsmsg))

allpapers = func.reduce(lambda a, b: a.union(b), [p for p, _, _, _ in stats])
allconfigs = func.reduce(lambda a, b: a.union(b), [c for _, c, _, _ in stats])
allckpts = func.reduce(lambda a, b: a.union(b), [c for _, _, c, _ in stats])
msglist = '\n'.join(x for _, _, _, x in stats)

modelzoo = f"""
# Model Zoo Statistics
* Number of checkpoints: {len(allckpts)}
* Number of configs: {len(allconfigs)}
* Number of papers: {len(allpapers)}
{msglist}
"""

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

0 comments on commit 7a1444a

Please sign in to comment.