From f31e0e930d2a1925812bb121178ae68ffe4d557b Mon Sep 17 00:00:00 2001 From: Jintao Lin <528557675@qq.com> Date: Thu, 19 Nov 2020 07:58:02 +0800 Subject: [PATCH] [docs] add modelzoo statistics readthedocs (#263) * add modelzoo statistics readthedocs * fix --- docs/conf.py | 9 +++++++++ docs/index.rst | 1 + docs/stat.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 docs/stat.py diff --git a/docs/conf.py b/docs/conf.py index d8b473b461..f472acb30a 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 @@ def get_version(): # 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 caa6677249..43f960ea04 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 0000000000..dc310de332 --- /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)