Skip to content

Commit

Permalink
[Feature] Auto modelzoo statistics (open-mmlab#327)
Browse files Browse the repository at this point in the history
* add stat.py

* update changelog

* update mmcv bound
  • Loading branch information
dreamerlin authored Nov 10, 2020
1 parent f8ea671 commit 7053406
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Highlights**

**New Features**
- Automatically add modelzoo statistics to readthedocs ([#327](https://github.com/open-mmlab/mmaction2/pull/327))

**Improvements**
- Add random seed for building filelists ([#323](https://github.com/open-mmlab/mmaction2/pull/323))
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def get_version():

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


def setup(app):
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Welcome to MMAction2's documentation!
:maxdepth: 2
:caption: Model Zoo

modelzoo.md
recognition_models.md
localization_models.md

Expand All @@ -32,6 +33,7 @@ Welcome to MMAction2's documentation!
tutorials/data_pipeline.md
tutorials/new_modules.md
tutorials/export_model.md
tutorials/customize_runtime.md

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If you build PyTorch from source instead of installing the prebuilt package, you
c. Install mmcv, we recommend you to install the pre-build mmcv as below.

```shell
pip install mmcv-full==latest+torch1.5.0+cu101 -f http://download.openmmlab.com/mmcv/dist/index.html
pip install mmcv-full==latest+torch1.5.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html
```

See [here](https://github.com/open-mmlab/mmcv#install-with-pip) for different versions of MMCV compatible to different PyTorch and CUDA versions.
Expand Down
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 functools as func
import glob
import re

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].replace('#', '')

# count papers
papers = set(x.lower().strip()
for x in re.findall(r'\btitle={(.*)}', content))
paperlist = '\n'.join(sorted(' - ' + x for x in papers))

# 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)
if 'mmaction' in x)

statsmsg = f"""
## [{title}]({f})
* 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)
2 changes: 1 addition & 1 deletion mmaction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .version import __version__

mmcv_minimum_version = '1.1.1'
mmcv_maximum_version = '1.2'
mmcv_maximum_version = '1.2.0'
mmcv_version = digit_version(mmcv.__version__)

assert (digit_version(mmcv_minimum_version) <= mmcv_version
Expand Down

0 comments on commit 7053406

Please sign in to comment.