Skip to content

Commit

Permalink
Auto get version info and git hash (#55)
Browse files Browse the repository at this point in the history
* Auto get version info and git hash

* bump 0.5.1 and update doc

* fixed docs

* Add change log
  • Loading branch information
xvjiarui authored Aug 11, 2020
1 parent 5e264c6 commit 4e29452
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 2,808 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ venv.bak/
# mypy
.mypy_cache/

mmseg/version.py
data
.vscode
.idea
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ This project is released under the [Apache 2.0 license](LICENSE).

## Changelog

v0.5.0 was released in 10/7/2020.
v0.5.1 was released in 11/08/2020.
Please refer to [changelog.md](docs/changelog.md) for details and release history.

## Benchmark and model zoo

Expand Down
15 changes: 15 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Changelog

### v0.5.1 (11/08/2020)
**Highlights**
- Support FP16 and more generalized OHEM
**Bug Fixes**
- Fixed Pascal VOC conversion script (#19)
- Fixed OHEM weight assign bug (#54)
- Fixed palette type when palette is not given (#27)
**New Features**
- Support FP16 (#21)
- Generalized OHEM (#54)
**Improvements**
- Add load-from flag (#33)
- Fixed training tricks doc about different learning rates of model (#26)
11 changes: 9 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@
project = 'MMSegmentation'
copyright = '2020-2020, OpenMMLab'
author = 'MMSegmentation Authors'
version_file = '../mmseg/version.py'


def get_version():
with open(version_file, 'r') as f:
exec(compile(f.read(), version_file, 'exec'))
return locals()['__version__']


# The full version, including alpha/beta/rc tags
with open('../mmseg/VERSION', 'r') as f:
release = f.read().strip()
release = get_version()

# -- General configuration ---------------------------------------------------

Expand Down
5 changes: 2 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ pip install -e . # or "python setup.py develop"

Note:

1. In `dev` mode, the git commit id will be written to the version number with step *d*, e.g. 0.5.0+c415a2e. The version will also be saved in trained models.
It is recommended that you run step *d* each time you pull some updates from github. If C++/CUDA codes are modified, then this step is compulsory.
1. The `version+git_hash` will also be saved in trained models meta, e.g. 0.5.0+c415a2e.

2. When MMsegmentation is installed on `dev` mode, any local modifications made to the code will take effect without the need to reinstall it (unless you submit some commits and want to update the version number).
2. When MMsegmentation is installed on `dev` mode, any local modifications made to the code will take effect without the need to reinstall it.

3. If you would like to use `opencv-python-headless` instead of `opencv-python`,
you can install it before installing MMCV.
Expand Down
2,724 changes: 0 additions & 2,724 deletions docs/model_zoo.json

This file was deleted.

1 change: 0 additions & 1 deletion mmseg/VERSION

This file was deleted.

31 changes: 29 additions & 2 deletions mmseg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
from .version import __version__, short_version, version_info
import mmcv

__all__ = ['__version__', 'short_version', 'version_info']
from .version import __version__, version_info

MMCV_MIN = '1.0.5'
MMCV_MAX = '1.0.5'


def digit_version(version_str):
digit_version = []
for x in version_str.split('.'):
if x.isdigit():
digit_version.append(int(x))
elif x.find('rc') != -1:
patch_version = x.split('rc')
digit_version.append(int(patch_version[0]) - 1)
digit_version.append(int(patch_version[1]))
return digit_version


mmcv_min_version = digit_version(MMCV_MIN)
mmcv_max_version = digit_version(MMCV_MAX)
mmcv_version = digit_version(mmcv.__version__)


assert (mmcv_min_version <= mmcv_version <= mmcv_max_version), \
f'MMCV=={mmcv.__version__} is used but incompatible. ' \
f'Please install mmcv>={mmcv_min_version}, <={mmcv_max_version}.'

__all__ = ['__version__', 'version_info']
4 changes: 2 additions & 2 deletions mmseg/utils/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import mmcv
import torch
import torchvision
from mmcv.utils.parrots_wrapper import get_build_config
from mmcv.utils import get_build_config, get_git_hash

import mmseg

Expand Down Expand Up @@ -53,7 +53,7 @@ def collect_env():
env_info['OpenCV'] = cv2.__version__

env_info['MMCV'] = mmcv.__version__
env_info['MMSegmentation'] = mmseg.__version__
env_info['MMSegmentation'] = f'{mmseg.__version__}+{get_git_hash()[:7]}'
try:
from mmcv.ops import get_compiler_version, get_compiling_cuda_version
env_info['MMCV Compiler'] = get_compiler_version()
Expand Down
18 changes: 18 additions & 0 deletions mmseg/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) Open-MMLab. All rights reserved.

__version__ = '0.5.1'


def parse_version_info(version_str):
version_info = []
for x in version_str.split('.'):
if x.isdigit():
version_info.append(int(x))
elif x.find('rc') != -1:
patch_version = x.split('rc')
version_info.append(int(patch_version[0]))
version_info.append(f'rc{patch_version[1]}')
return tuple(version_info)


version_info = parse_version_info(__version__)
79 changes: 9 additions & 70 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,19 @@
import os
import subprocess
import time
from setuptools import find_packages, setup

version_file = 'mmseg/version.py'

def readme():
with open('README.md', encoding='utf-8') as f:
content = f.read()
return content


def get_git_hash():

def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH', 'HOME']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(
cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
return out

try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
sha = out.strip().decode('ascii')
except OSError:
sha = 'unknown'

return sha


def get_hash():
if os.path.exists('.git'):
sha = get_git_hash()[:7]
elif os.path.exists(version_file):
try:
from mmseg.version import __version__
sha = __version__.split('+')[-1]
except ImportError:
raise ImportError('Unable to get git version')
else:
sha = 'unknown'

return sha


def write_version_py():
content = """# GENERATED VERSION FILE
# TIME: {}
__version__ = '{}'
short_version = '{}'
version_info = ({})
"""
sha = get_hash()
with open('mmseg/VERSION', 'r') as f:
SHORT_VERSION = f.read().strip()
VERSION_INFO = ', '.join(SHORT_VERSION.split('.'))
VERSION = SHORT_VERSION + '+' + sha

version_file_str = content.format(time.asctime(), VERSION, SHORT_VERSION,
VERSION_INFO)
with open(version_file, 'w') as f:
f.write(version_file_str)
version_file = 'mmseg/version.py'


def get_version():
with open(version_file, 'r') as f:
exec(compile(f.read(), version_file, 'exec'))
import sys
# return short version for sdist
if 'sdist' in sys.argv or 'bdist_wheel' in sys.argv:
return locals()['short_version']
else:
return locals()['__version__']
return locals()['__version__']


def parse_requirements(fname='requirements.txt', with_version=True):
Expand Down Expand Up @@ -155,11 +93,12 @@ def gen_packages_items():


if __name__ == '__main__':
write_version_py()
setup(
name='mmsegmentation',
version=get_version(),
description='Open MMLab Semantic Segmentation Toolbox and Benchmark',
long_description=readme(),
long_description_content_type='text/markdown',
author='MMSegmentation Authors',
author_email='openmmlab@gmail.com',
keywords='computer vision, semantic segmentation',
Expand Down
4 changes: 2 additions & 2 deletions tools/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import mmcv
import torch
from mmcv.runner import init_dist
from mmcv.utils import Config, DictAction
from mmcv.utils import Config, DictAction, get_git_hash

from mmseg import __version__
from mmseg.apis import set_random_seed, train_segmentor
Expand Down Expand Up @@ -141,7 +141,7 @@ def main():
# save mmseg version, config file content and class names in
# checkpoints as meta data
cfg.checkpoint_config.meta = dict(
mmseg_version=__version__,
mmseg_version=f'{__version__}+{get_git_hash()[:7]}',
config=cfg.pretty_text,
CLASSES=datasets[0].CLASSES,
PALETTE=datasets[0].PALETTE)
Expand Down

0 comments on commit 4e29452

Please sign in to comment.