Skip to content

Commit 3b53fe1

Browse files
authored
Add python path in scripts (#2625)
* add python path in scripts * Make python path work * Shorter path * Add docs * Change dist scripts * Change slurm example
1 parent 99c879d commit 3b53fe1

8 files changed

+18
-24
lines changed

README.md

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

4141
## Changelog
4242

43-
v2.0.0 was released in 5/5/2020.
43+
v2.0.0 was released in 6/5/2020.
4444
Please refer to [changelog.md](docs/changelog.md) for details and release history.
4545

4646
## Benchmark and model zoo

docs/changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Changelog
22

3-
### v2.0.0 (4/5/2020)
3+
### v2.0.0 (6/5/2020)
44
In this release, we made lots of major refactoring and modifications.
55

66
1. **Faster speed**. We optimize the training and inference speed for common models, achieving up to 30% speedup for training and 25% for inference. Please refer to [model zoo](model_zoo.md#comparison-with-detectron2) for details.

docs/getting_started.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ Difference between `resume-from` and `load-from`:
288288
If you run MMDetection on a cluster managed with [slurm](https://slurm.schedmd.com/), you can use the script `slurm_train.sh`. (This script also supports single machine training.)
289289

290290
```shell
291-
./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} ${WORK_DIR} [${GPUS}]
291+
[GPUS=${GPUS}] ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} ${CONFIG_FILE} ${WORK_DIR}
292292
```
293293

294294
Here is an example of using 16 GPUs to train Mask R-CNN on the dev partition.
295295

296296
```shell
297-
./tools/slurm_train.sh dev mask_r50_1x configs/mask_rcnn_r50_fpn_1x_coco.py /nfs/xxxx/mask_rcnn_r50_fpn_1x 16
297+
GPUS=16 ./tools/slurm_train.sh dev mask_r50_1x configs/mask_rcnn_r50_fpn_1x_coco.py /nfs/xxxx/mask_rcnn_r50_fpn_1x
298298
```
299299

300300
You can check [slurm_train.sh](https://github.com/open-mmlab/mmdetection/blob/master/tools/slurm_train.sh) for full arguments and environment variables.
@@ -330,8 +330,8 @@ dist_params = dict(backend='nccl', port=29501)
330330
Then you can launch two jobs with `config1.py` ang `config2.py`.
331331

332332
```shell
333-
CUDA_VISIBLE_DEVICES=0,1,2,3 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config1.py ${WORK_DIR} 4
334-
CUDA_VISIBLE_DEVICES=4,5,6,7 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config2.py ${WORK_DIR} 4
333+
CUDA_VISIBLE_DEVICES=0,1,2,3 GPUS=4 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config1.py ${WORK_DIR}
334+
CUDA_VISIBLE_DEVICES=4,5,6,7 GPUS=4 ./tools/slurm_train.sh ${PARTITION} ${JOB_NAME} config2.py ${WORK_DIR}
335335
```
336336

337337
## Useful tools

docs/install.md

+3-9
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,10 @@ pip install -v -e .
128128

129129
### Using multiple MMDetection versions
130130

131-
If there are more than one mmdetection on your machine, and you want to use them alternatively, the recommended way is to create multiple conda environments and use different environments for different versions.
131+
The train and test scripts already modify the `PYTHONPATH` to ensure the script use the MMDetection in the current directory.
132132

133-
Another way is to insert the following code to the main scripts (`train.py`, `test.py` or any other scripts you run)
134-
```python
135-
import os.path as osp
136-
import sys
137-
sys.path.insert(0, osp.join(osp.dirname(osp.abspath(__file__)), '../'))
138-
```
133+
To use the default MMDetection installed in the environment rather than that you are working with, you can remove the following line in those scripts
139134

140-
Or run the following command in the terminal of corresponding folder to temporally use the current one.
141135
```shell
142-
export PYTHONPATH=`pwd`:$PYTHONPATH
136+
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
143137
```

tools/dist_test.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env bash
22

3-
PYTHON=${PYTHON:-"python"}
4-
53
CONFIG=$1
64
CHECKPOINT=$2
75
GPUS=$3
86
PORT=${PORT:-29500}
97

10-
$PYTHON -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \
8+
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
9+
python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \
1110
$(dirname "$0")/test.py $CONFIG $CHECKPOINT --launcher pytorch ${@:4}

tools/dist_train.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env bash
22

3-
PYTHON=${PYTHON:-"python"}
4-
53
CONFIG=$1
64
GPUS=$2
75
PORT=${PORT:-29500}
86

9-
$PYTHON -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \
7+
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
8+
python -m torch.distributed.launch --nproc_per_node=$GPUS --master_port=$PORT \
109
$(dirname "$0")/train.py $CONFIG --launcher pytorch ${@:3}

tools/slurm_test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
set -x
4-
export PYTHONPATH=`pwd`:$PYTHONPATH
4+
55
PARTITION=$1
66
JOB_NAME=$2
77
CONFIG=$3
@@ -12,6 +12,7 @@ CPUS_PER_TASK=${CPUS_PER_TASK:-5}
1212
PY_ARGS=${@:5}
1313
SRUN_ARGS=${SRUN_ARGS:-""}
1414

15+
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
1516
srun -p ${PARTITION} \
1617
--job-name=${JOB_NAME} \
1718
--gres=gpu:${GPUS_PER_NODE} \

tools/slurm_train.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ PARTITION=$1
66
JOB_NAME=$2
77
CONFIG=$3
88
WORK_DIR=$4
9-
GPUS=${5:-8}
9+
GPUS=${GPUS:-8}
1010
GPUS_PER_NODE=${GPUS_PER_NODE:-8}
1111
CPUS_PER_TASK=${CPUS_PER_TASK:-5}
1212
SRUN_ARGS=${SRUN_ARGS:-""}
13-
PY_ARGS=${PY_ARGS:-"--validate"}
13+
PY_ARGS=${@:5}
1414

15+
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH \
1516
srun -p ${PARTITION} \
1617
--job-name=${JOB_NAME} \
1718
--gres=gpu:${GPUS_PER_NODE} \

0 commit comments

Comments
 (0)