Skip to content

Commit 00f56eb

Browse files
nizhibxvjiarui
andauthored
Add load-from flag (open-mmlab#33)
* Add load-from flag * minor update Co-authored-by: Jiarui XU <[email protected]>
1 parent 2b801de commit 00f56eb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/getting_started.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,12 @@ Optional arguments are:
241241

242242
- `--no-validate` (**not suggested**): By default, the codebase will perform evaluation at every k iterations during the training. To disable this behavior, use `--no-validate`.
243243
- `--work-dir ${WORK_DIR}`: Override the working directory specified in the config file.
244-
- `--resume-from ${CHECKPOINT_FILE}`: Resume from a previous checkpoint file.
244+
- `--resume-from ${CHECKPOINT_FILE}`: Resume from a previous checkpoint file (to continue the training process).
245+
- `--load-from ${CHECKPOINT_FILE}`: Load weights from a checkpoint file (to start finetuning for another task).
245246

246247
Difference between `resume-from` and `load-from`:
247-
`resume-from` loads both the model weights and optimizer status, and the iteration number is also inherited from the specified checkpoint. It is usually used for resuming the training process that is interrupted accidentally.
248-
`load-from` only loads the model weights and the training iteration starts from 0. It is usually used for finetuning.
248+
- `resume-from` loads both the model weights and optimizer state including the iteration number.
249+
- `load-from` loads only the model weights, starts the training from iteration 0.
249250

250251
### Train with multiple machines
251252

tools/train.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def parse_args():
2020
parser = argparse.ArgumentParser(description='Train a segmentor')
2121
parser.add_argument('config', help='train config file path')
2222
parser.add_argument('--work_dir', help='the dir to save logs and models')
23+
parser.add_argument(
24+
'--load-from', help='the checkpoint file to load weights from')
2325
parser.add_argument(
2426
'--resume-from', help='the checkpoint file to resume from')
2527
parser.add_argument(
@@ -76,6 +78,8 @@ def main():
7678
# use config filename as default work_dir if cfg.work_dir is None
7779
cfg.work_dir = osp.join('./work_dirs',
7880
osp.splitext(osp.basename(args.config))[0])
81+
if args.load_from is not None:
82+
cfg.load_from = args.load_from
7983
if args.resume_from is not None:
8084
cfg.resume_from = args.resume_from
8185
if args.gpu_ids is not None:

0 commit comments

Comments
 (0)