Skip to content

Commit 0f702f4

Browse files
authoredAug 11, 2020
Auto get version info and git hash (open-mmlab#55)
* Auto get version info and git hash * bump 0.5.1 and update doc * fixed docs * Add change log
1 parent 99e3e5e commit 0f702f4

12 files changed

+88
-2808
lines changed
 

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ venv.bak/
103103
# mypy
104104
.mypy_cache/
105105

106-
mmseg/version.py
107106
data
108107
.vscode
109108
.idea

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ This project is released under the [Apache 2.0 license](LICENSE).
4444

4545
## Changelog
4646

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

4950
## Benchmark and model zoo
5051

‎docs/changelog.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Changelog
2+
3+
### v0.5.1 (11/08/2020)
4+
**Highlights**
5+
- Support FP16 and more generalized OHEM
6+
**Bug Fixes**
7+
- Fixed Pascal VOC conversion script (#19)
8+
- Fixed OHEM weight assign bug (#54)
9+
- Fixed palette type when palette is not given (#27)
10+
**New Features**
11+
- Support FP16 (#21)
12+
- Generalized OHEM (#54)
13+
**Improvements**
14+
- Add load-from flag (#33)
15+
- Fixed training tricks doc about different learning rates of model (#26)

‎docs/conf.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@
2020
project = 'MMSegmentation'
2121
copyright = '2020-2020, OpenMMLab'
2222
author = 'MMSegmentation Authors'
23+
version_file = '../mmseg/version.py'
24+
25+
26+
def get_version():
27+
with open(version_file, 'r') as f:
28+
exec(compile(f.read(), version_file, 'exec'))
29+
return locals()['__version__']
30+
2331

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

2835
# -- General configuration ---------------------------------------------------
2936

‎docs/install.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ pip install -e . # or "python setup.py develop"
5454

5555
Note:
5656

57-
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.
58-
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.
57+
1. The `version+git_hash` will also be saved in trained models meta, e.g. 0.5.0+c415a2e.
5958

60-
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).
59+
2. When MMsegmentation is installed on `dev` mode, any local modifications made to the code will take effect without the need to reinstall it.
6160

6261
3. If you would like to use `opencv-python-headless` instead of `opencv-python`,
6362
you can install it before installing MMCV.

‎docs/model_zoo.json

-2,724
This file was deleted.

‎mmseg/VERSION

-1
This file was deleted.

‎mmseg/__init__.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1-
from .version import __version__, short_version, version_info
1+
import mmcv
22

3-
__all__ = ['__version__', 'short_version', 'version_info']
3+
from .version import __version__, version_info
4+
5+
MMCV_MIN = '1.0.5'
6+
MMCV_MAX = '1.0.5'
7+
8+
9+
def digit_version(version_str):
10+
digit_version = []
11+
for x in version_str.split('.'):
12+
if x.isdigit():
13+
digit_version.append(int(x))
14+
elif x.find('rc') != -1:
15+
patch_version = x.split('rc')
16+
digit_version.append(int(patch_version[0]) - 1)
17+
digit_version.append(int(patch_version[1]))
18+
return digit_version
19+
20+
21+
mmcv_min_version = digit_version(MMCV_MIN)
22+
mmcv_max_version = digit_version(MMCV_MAX)
23+
mmcv_version = digit_version(mmcv.__version__)
24+
25+
26+
assert (mmcv_min_version <= mmcv_version <= mmcv_max_version), \
27+
f'MMCV=={mmcv.__version__} is used but incompatible. ' \
28+
f'Please install mmcv>={mmcv_min_version}, <={mmcv_max_version}.'
29+
30+
__all__ = ['__version__', 'version_info']

‎mmseg/utils/collect_env.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import mmcv
88
import torch
99
import torchvision
10-
from mmcv.utils.parrots_wrapper import get_build_config
10+
from mmcv.utils import get_build_config, get_git_hash
1111

1212
import mmseg
1313

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

5555
env_info['MMCV'] = mmcv.__version__
56-
env_info['MMSegmentation'] = mmseg.__version__
56+
env_info['MMSegmentation'] = f'{mmseg.__version__}+{get_git_hash()[:7]}'
5757
try:
5858
from mmcv.ops import get_compiler_version, get_compiling_cuda_version
5959
env_info['MMCV Compiler'] = get_compiler_version()

‎mmseg/version.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) Open-MMLab. All rights reserved.
2+
3+
__version__ = '0.5.1'
4+
5+
6+
def parse_version_info(version_str):
7+
version_info = []
8+
for x in version_str.split('.'):
9+
if x.isdigit():
10+
version_info.append(int(x))
11+
elif x.find('rc') != -1:
12+
patch_version = x.split('rc')
13+
version_info.append(int(patch_version[0]))
14+
version_info.append(f'rc{patch_version[1]}')
15+
return tuple(version_info)
16+
17+
18+
version_info = parse_version_info(__version__)

‎setup.py

+9-70
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,19 @@
1-
import os
2-
import subprocess
3-
import time
41
from setuptools import find_packages, setup
52

6-
version_file = 'mmseg/version.py'
3+
4+
def readme():
5+
with open('README.md', encoding='utf-8') as f:
6+
content = f.read()
7+
return content
78

89

9-
def get_git_hash():
10-
11-
def _minimal_ext_cmd(cmd):
12-
# construct minimal environment
13-
env = {}
14-
for k in ['SYSTEMROOT', 'PATH', 'HOME']:
15-
v = os.environ.get(k)
16-
if v is not None:
17-
env[k] = v
18-
# LANGUAGE is used on win32
19-
env['LANGUAGE'] = 'C'
20-
env['LANG'] = 'C'
21-
env['LC_ALL'] = 'C'
22-
out = subprocess.Popen(
23-
cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
24-
return out
25-
26-
try:
27-
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
28-
sha = out.strip().decode('ascii')
29-
except OSError:
30-
sha = 'unknown'
31-
32-
return sha
33-
34-
35-
def get_hash():
36-
if os.path.exists('.git'):
37-
sha = get_git_hash()[:7]
38-
elif os.path.exists(version_file):
39-
try:
40-
from mmseg.version import __version__
41-
sha = __version__.split('+')[-1]
42-
except ImportError:
43-
raise ImportError('Unable to get git version')
44-
else:
45-
sha = 'unknown'
46-
47-
return sha
48-
49-
50-
def write_version_py():
51-
content = """# GENERATED VERSION FILE
52-
# TIME: {}
53-
54-
__version__ = '{}'
55-
short_version = '{}'
56-
version_info = ({})
57-
"""
58-
sha = get_hash()
59-
with open('mmseg/VERSION', 'r') as f:
60-
SHORT_VERSION = f.read().strip()
61-
VERSION_INFO = ', '.join(SHORT_VERSION.split('.'))
62-
VERSION = SHORT_VERSION + '+' + sha
63-
64-
version_file_str = content.format(time.asctime(), VERSION, SHORT_VERSION,
65-
VERSION_INFO)
66-
with open(version_file, 'w') as f:
67-
f.write(version_file_str)
10+
version_file = 'mmseg/version.py'
6811

6912

7013
def get_version():
7114
with open(version_file, 'r') as f:
7215
exec(compile(f.read(), version_file, 'exec'))
73-
import sys
74-
# return short version for sdist
75-
if 'sdist' in sys.argv or 'bdist_wheel' in sys.argv:
76-
return locals()['short_version']
77-
else:
78-
return locals()['__version__']
16+
return locals()['__version__']
7917

8018

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

15694

15795
if __name__ == '__main__':
158-
write_version_py()
15996
setup(
16097
name='mmsegmentation',
16198
version=get_version(),
16299
description='Open MMLab Semantic Segmentation Toolbox and Benchmark',
100+
long_description=readme(),
101+
long_description_content_type='text/markdown',
163102
author='MMSegmentation Authors',
164103
author_email='openmmlab@gmail.com',
165104
keywords='computer vision, semantic segmentation',

‎tools/train.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import mmcv
88
import torch
99
from mmcv.runner import init_dist
10-
from mmcv.utils import Config, DictAction
10+
from mmcv.utils import Config, DictAction, get_git_hash
1111

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

0 commit comments

Comments
 (0)
Please sign in to comment.