Test a model

  • single GPU

  • single node multiple GPU

  • multiple node

You can use the following commands to infer a dataset.

# single-gpu
python tools/ ${CONFIG_FILE} ${CHECKPOINT_FILE} [optional arguments]

# multi-gpu
./tools/ ${CONFIG_FILE} ${CHECKPOINT_FILE} ${GPU_NUM} [optional arguments]

# multi-node in slurm environment
python tools/ ${CONFIG_FILE} ${CHECKPOINT_FILE} [optional arguments] --launcher slurm


Inference rotated RetinaNet on DOTA-1.0 dataset. (Please change the data_root firstly.)

python ./tools/ \
  configs/rotated_retinanet/ \
  checkpoints/SOME_CHECKPOINT.pth --eval mAP

You can also visualize the results.

python ./tools/ \
  configs/rotated_retinanet/ \
  checkpoints/SOME_CHECKPOINT.pth \
  --show-dir work_dirs/vis

Further, you can also generate compressed files for online submission.

python ./tools/  \
  configs/rotated_retinanet/ \
  checkpoints/SOME_CHECKPOINT.pth 1 --format-only \
  --eval-options submission_dir=work_dirs/Task1_results

Train a model

Train with a single GPU

python tools/ ${CONFIG_FILE} [optional arguments]

If you want to specify the working directory in the command, you can add an argument --work_dir ${YOUR_WORK_DIR}.

Train with multiple GPUs

./tools/ ${CONFIG_FILE} ${GPU_NUM} [optional arguments]

Optional arguments are:

  • --no-validate (not suggested): By default, the codebase will perform evaluation during the training. To disable this behavior, use --no-validate.

  • --work-dir ${WORK_DIR}: Override the working directory specified in the config file.

  • --resume-from ${CHECKPOINT_FILE}: Resume from a previous checkpoint file.

Difference between resume-from and load-from: resume-from loads both the model weights and optimizer status, and the epoch is also inherited from the specified checkpoint. It is usually used for resuming the training process that is interrupted accidentally. load-from only loads the model weights and the training epoch starts from 0. It is usually used for finetuning.

Train with multiple machines

If you run MMRotate on a cluster managed with slurm, you can use the script (This script also supports single machine training.)


If you have just multiple machines connected with ethernet, you can refer to PyTorch launch utility. Usually it is slow if you do not have high speed networking like InfiniBand.

Launch multiple jobs on a single machine

If you launch multiple jobs on a single machine, e.g., 2 jobs of 4-GPU training on a machine with 8 GPUs, you need to specify different ports (29500 by default) for each job to avoid communication conflict.

If you use to launch training jobs, you can set the port in commands.

CUDA_VISIBLE_DEVICES=0,1,2,3 PORT=29500 ./tools/ ${CONFIG_FILE} 4
CUDA_VISIBLE_DEVICES=4,5,6,7 PORT=29501 ./tools/ ${CONFIG_FILE} 4

If you use launch training jobs with Slurm, you need to modify the config files (usually the 6th line from the bottom in config files) to set different communication ports.


dist_params = dict(backend='nccl', port=29500)


dist_params = dict(backend='nccl', port=29501)

Then you can launch two jobs with ang

Read the Docs v: v0.1.0
On Read the Docs
Project Home

Free document hosting provided by Read the Docs.