From 713791a52c11f1fc15367b21cb9d96b728624165 Mon Sep 17 00:00:00 2001 From: YiweiJiang2015 Date: Thu, 15 Apr 2021 09:49:21 +0200 Subject: [PATCH 1/2] add fine tune toggle to avoid saved config file being overridden by outer config during inference --- parse_config.py | 3 ++- train.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/parse_config.py b/parse_config.py index 309f153e..7cbc5f57 100644 --- a/parse_config.py +++ b/parse_config.py @@ -69,8 +69,9 @@ def from_args(cls, args, options=''): cfg_fname = Path(args.config) config = read_json(cfg_fname) - if args.config and resume: + if args.config and resume and args.fine_tune: # update new config for fine-tuning + # if not fine tune, the saved config will remain as it is config.update(read_json(args.config)) # parse custom cli options into dictionary diff --git a/train.py b/train.py index a43f6c47..26012e88 100644 --- a/train.py +++ b/train.py @@ -58,6 +58,8 @@ def main(config): args = argparse.ArgumentParser(description='PyTorch Template') args.add_argument('-c', '--config', default=None, type=str, help='config file path (default: None)') + args.add_argument('-ft', '--fine-tune', default=False, type=bool, + help='fine tune pretrained model or not. If True, the saved config will be overridden by outer config') args.add_argument('-r', '--resume', default=None, type=str, help='path to latest checkpoint (default: None)') args.add_argument('-d', '--device', default=None, type=str, From 0a7090cdff0126a2609ae2327416eb9f14de1410 Mon Sep 17 00:00:00 2001 From: YiweiJiang2015 Date: Thu, 15 Apr 2021 10:10:41 +0200 Subject: [PATCH 2/2] also add --fine-tune to test.py --- test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test.py b/test.py index fc084fac..c639e0ea 100644 --- a/test.py +++ b/test.py @@ -72,6 +72,8 @@ def main(config): args = argparse.ArgumentParser(description='PyTorch Template') args.add_argument('-c', '--config', default=None, type=str, help='config file path (default: None)') + args.add_argument('-ft', '--fine-tune', default=False, type=bool, + help='fine tune pretrained model or not. If True, the saved config will be overridden by outer config') args.add_argument('-r', '--resume', default=None, type=str, help='path to latest checkpoint (default: None)') args.add_argument('-d', '--device', default=None, type=str,