register_config_arguments

tfsnippet.utils.register_config_arguments(config, parser, prefix=None, title=None, description=None, sort_keys=False)

Register config to the specified argument parser.

Usage:

class YourConfig(Config):
    max_epoch = 1000
    learning_rate = 0.01
    activation = ConfigField(
        str, default='leaky_relu', choices=['relu', 'leaky_relu'])

# First, you should obtain an instance of your config object
config = YourConfig()

# You can then parse config values from CLI arguments.
# For example, if sys.argv[1:] == ['--max_epoch=2000']:
from argparse import ArgumentParser
parser = ArgumentParser()
spt.register_config_arguments(config, parser)
parser.parse_args(sys.argv[1:])

# Now you can access the config value `config.max_epoch == 2000`
print(config.max_epoch)
Parameters:
  • config (Config) – The config object.
  • parser (ArgumentParser) – The argument parser.
  • prefix (str) – Optional prefix of the config keys. new_config_key = prefix + ‘.’ + old_config_key
  • title (str) – If specified, will create an argument group to collect all the config arguments.
  • description (str) – The description of the argument group.
  • sort_keys (bool) – Whether or not to sort the config keys before registering to the parser? (default False)