Feng Wang commited on
Commit
f797b2c
·
1 Parent(s): 3f067c3

feat(exp,tools): support installation for pip (#1020)

Browse files
README.md CHANGED
@@ -120,22 +120,23 @@ ln -s /path/to/your/COCO ./datasets/COCO
120
  Step2. Reproduce our results on COCO by specifying -n:
121
 
122
  ```shell
123
- python tools/train.py -n yolox-s -d 8 -b 64 --fp16 -o [--cache]
124
- yolox-m
125
- yolox-l
126
- yolox-x
127
  ```
128
  * -d: number of gpu devices
129
  * -b: total batch size, the recommended number for -b is num-gpu * 8
130
  * --fp16: mixed precision training
131
  * --cache: caching imgs into RAM to accelarate training, which need large system RAM.
132
 
 
133
  When using -f, the above commands are equivalent to:
134
  ```shell
135
- python tools/train.py -f exps/default/yolox_s.py -d 8 -b 64 --fp16 -o [--cache]
136
- exps/default/yolox_m.py
137
- exps/default/yolox_l.py
138
- exps/default/yolox_x.py
139
  ```
140
 
141
  **Multi Machine Training**
@@ -154,6 +155,12 @@ On the second machine, run
154
  python tools/train.py -n yolox-s -b 128 --dist-url tcp://123.123.123.123:12312 --num-machines 2 --machine-rank 1
155
  ```
156
 
 
 
 
 
 
 
157
  </details>
158
 
159
 
@@ -163,10 +170,10 @@ python tools/train.py -n yolox-s -b 128 --dist-url tcp://123.123.123.123:12312 -
163
  We support batch testing for fast evaluation:
164
 
165
  ```shell
166
- python tools/eval.py -n yolox-s -c yolox_s.pth -b 64 -d 8 --conf 0.001 [--fp16] [--fuse]
167
- yolox-m
168
- yolox-l
169
- yolox-x
170
  ```
171
  * --fuse: fuse conv and bn
172
  * -d: number of GPUs used for evaluation. DEFAULT: All GPUs available will be used.
@@ -174,10 +181,10 @@ python tools/eval.py -n yolox-s -c yolox_s.pth -b 64 -d 8 --conf 0.001 [--fp16]
174
 
175
  To reproduce speed test, we use the following command:
176
  ```shell
177
- python tools/eval.py -n yolox-s -c yolox_s.pth -b 1 -d 1 --conf 0.001 --fp16 --fuse
178
- yolox-m
179
- yolox-l
180
- yolox-x
181
  ```
182
 
183
  </details>
 
120
  Step2. Reproduce our results on COCO by specifying -n:
121
 
122
  ```shell
123
+ python -m yolox.tools.train -n yolox-s -d 8 -b 64 --fp16 -o [--cache]
124
+ yolox-m
125
+ yolox-l
126
+ yolox-x
127
  ```
128
  * -d: number of gpu devices
129
  * -b: total batch size, the recommended number for -b is num-gpu * 8
130
  * --fp16: mixed precision training
131
  * --cache: caching imgs into RAM to accelarate training, which need large system RAM.
132
 
133
+
134
  When using -f, the above commands are equivalent to:
135
  ```shell
136
+ python -m yolox.tools.train -f exps/default/yolox_s.py -d 8 -b 64 --fp16 -o [--cache]
137
+ exps/default/yolox_m.py
138
+ exps/default/yolox_l.py
139
+ exps/default/yolox_x.py
140
  ```
141
 
142
  **Multi Machine Training**
 
155
  python tools/train.py -n yolox-s -b 128 --dist-url tcp://123.123.123.123:12312 --num-machines 2 --machine-rank 1
156
  ```
157
 
158
+ **Others**
159
+ See more information with the following command:
160
+ ```shell
161
+ python -m yolox.tools.train --help
162
+ ```
163
+
164
  </details>
165
 
166
 
 
170
  We support batch testing for fast evaluation:
171
 
172
  ```shell
173
+ python -m yolox.tools.eval -n yolox-s -c yolox_s.pth -b 64 -d 8 --conf 0.001 [--fp16] [--fuse]
174
+ yolox-m
175
+ yolox-l
176
+ yolox-x
177
  ```
178
  * --fuse: fuse conv and bn
179
  * -d: number of GPUs used for evaluation. DEFAULT: All GPUs available will be used.
 
181
 
182
  To reproduce speed test, we use the following command:
183
  ```shell
184
+ python -m yolox.tools.eval -n yolox-s -c yolox_s.pth -b 1 -d 1 --conf 0.001 --fp16 --fuse
185
+ yolox-m
186
+ yolox-l
187
+ yolox-x
188
  ```
189
 
190
  </details>
exps/default/{nano.py → yolox_nano.py} RENAMED
File without changes
yolox/exp/build.py CHANGED
@@ -18,24 +18,13 @@ def get_exp_by_file(exp_file):
18
 
19
 
20
  def get_exp_by_name(exp_name):
21
- import yolox
22
-
23
- yolox_path = os.path.dirname(os.path.dirname(yolox.__file__))
24
- filedict = {
25
- "yolox-s": "yolox_s.py",
26
- "yolox-m": "yolox_m.py",
27
- "yolox-l": "yolox_l.py",
28
- "yolox-x": "yolox_x.py",
29
- "yolox-tiny": "yolox_tiny.py",
30
- "yolox-nano": "nano.py",
31
- "yolov3": "yolov3.py",
32
- }
33
- filename = filedict[exp_name]
34
- exp_path = os.path.join(yolox_path, "exps", "default", filename)
35
- return get_exp_by_file(exp_path)
36
-
37
-
38
- def get_exp(exp_file, exp_name):
39
  """
40
  get Exp object by file or name. If exp_file and exp_name
41
  are both provided, get Exp by exp_file.
 
18
 
19
 
20
  def get_exp_by_name(exp_name):
21
+ exp = exp_name.replace("-", "_") # convert string like "yolox-s" to "yolox_s"
22
+ module_name = ".".join(["yolox", "exp", "default", exp])
23
+ exp_object = importlib.import_module(module_name).Exp()
24
+ return exp_object
25
+
26
+
27
+ def get_exp(exp_file=None, exp_name=None):
 
 
 
 
 
 
 
 
 
 
 
28
  """
29
  get Exp object by file or name. If exp_file and exp_name
30
  are both provided, get Exp by exp_file.
yolox/exp/default/__init__.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
4
+
5
+ # This file is used for package installation and find default exp file
6
+
7
+ import importlib
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _EXP_PATH = Path(__file__).resolve().parent.parent.parent.parent / "exps" / "default"
12
+
13
+ if _EXP_PATH.is_dir():
14
+ # This is true only for in-place installation (pip install -e, setup.py develop),
15
+ # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
16
+
17
+ class _ExpFinder(importlib.abc.MetaPathFinder):
18
+
19
+ def find_spec(self, name, path, target=None):
20
+ if not name.startswith("yolox.exp.default"):
21
+ return
22
+ project_name = name.split(".")[-1] + ".py"
23
+ target_file = _EXP_PATH / project_name
24
+ if not target_file.is_file():
25
+ return
26
+ return importlib.util.spec_from_file_location(name, target_file)
27
+
28
+ sys.meta_path.append(_ExpFinder())
yolox/tools/__init__.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # -*- coding:utf-8 -*-
3
+ # Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
4
+
5
+ # This file is used for package installation. Script of train/eval/export will be available.
6
+
7
+ import importlib
8
+ import sys
9
+ from pathlib import Path
10
+
11
+ _TOOLS_PATH = Path(__file__).resolve().parent.parent.parent / "tools"
12
+
13
+ if _TOOLS_PATH.is_dir():
14
+ # This is true only for in-place installation (pip install -e, setup.py develop),
15
+ # where setup(package_dir=) does not work: https://github.com/pypa/setuptools/issues/230
16
+
17
+ class _PathFinder(importlib.abc.MetaPathFinder):
18
+
19
+ def find_spec(self, name, path, target=None):
20
+ if not name.startswith("yolox.tools."):
21
+ return
22
+ project_name = name.split(".")[-1] + ".py"
23
+ target_file = _TOOLS_PATH / project_name
24
+ if not target_file.is_file():
25
+ return
26
+ return importlib.util.spec_from_file_location(name, target_file)
27
+
28
+ sys.meta_path.append(_PathFinder())