This PR contains a new feature: configurable CLI options.
Following is an example of adding two flags with this, which is included in train.py.
# simple class-like object having 3 attributes, `flags`, `type`, `target`.
CustomArgs = collections.namedtuple('CustomArgs', 'flags type target')
options = [
CustomArgs(['--lr', '--learning_rate'], type=float, target=('optimizer', 'args', 'lr')),
CustomArgs(['--bs', '--batch_size'], type=int, target=('data_loader', 'args', 'batch_size'))
# options added here can be modified by command line flags.
]
target here is a sequence of keys which are required to access that option in the config dict.
In this example, target of learning rate option is ('optimizer', 'args', 'lr') because config['optimizer']['args']['lr'] points to the learning rate.
python3 train.py -c config.json --bs 256 runs training with options given in config.json except for the batch size which is increased to 256 by command line options.
This PR contains a new feature: configurable CLI options. Following is an example of adding two flags with this, which is included in
train.py
.target
here is a sequence of keys which are required to access that option in the config dict. In this example,target
of learning rate option is('optimizer', 'args', 'lr')
becauseconfig['optimizer']['args']['lr']
points to the learning rate.python3 train.py -c config.json --bs 256
runs training with options given inconfig.json
except for thebatch size
which is increased to 256 by command line options.