diff --git a/docs/conf.py b/docs/conf.py index d8b473b46..f472acb30 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,6 +11,7 @@ # documentation root, use os.path.abspath to make it absolute, like shown here. # import os +import subprocess import sys sys.path.insert(0, os.path.abspath('..')) @@ -77,3 +78,11 @@ html_theme = 'sphinx_rtd_theme' # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] + + +def builder_inited_handler(app): + subprocess.run(['./stat.py']) + + +def setup(app): + app.connect('builder-inited', builder_inited_handler) diff --git a/docs/index.rst b/docs/index.rst index caa667724..43f960ea0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,6 +7,7 @@ Welcome to MMSegmenation's documentation! install.md getting_started.md config.md + modelzoo_statistics.md model_zoo.md .. toctree:: diff --git a/docs/stat.py b/docs/stat.py new file mode 100644 index 000000000..dc310de33 --- /dev/null +++ b/docs/stat.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import glob +import os.path as osp +import re + +url_prefix = 'https://github.com/open-mmlab/mmsegmentation/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() + + title = content.split('\n')[0].replace('#', '') + titles.append(title) + ckpts = set(x.lower().strip() + for x in re.findall(r'https?://download.*\.pth', content) + if 'mmsegmentation' in x) + num_ckpts += len(ckpts) + statsmsg = f""" +\t* [{title}]({url}) ({len(ckpts)} ckpts) +""" + stats.append((title, ckpts, statsmsg)) + +msglist = '\n'.join(x for _, _, x in stats) + +modelzoo = f""" +# Model Zoo Statistics + +* Number of papers: {len(titles)} +* Number of checkpoints: {num_ckpts} +{msglist} +""" + +with open('modelzoo_statistics.md', 'w') as f: + f.write(modelzoo)