Python absl.flags.DEFINE_enum() Examples
The following are 30
code examples of absl.flags.DEFINE_enum().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
absl.flags
, or try the search function
.
Example #1
Source File: flags.py From benchmarks with Apache License 2.0 | 7 votes |
def define_flags(specs=None): """Define a command line flag for each ParamSpec in flags.param_specs.""" specs = specs or param_specs define_flag = { 'boolean': absl_flags.DEFINE_boolean, 'float': absl_flags.DEFINE_float, 'integer': absl_flags.DEFINE_integer, 'string': absl_flags.DEFINE_string, 'enum': absl_flags.DEFINE_enum, 'list': absl_flags.DEFINE_list } for name, param_spec in six.iteritems(specs): if param_spec.flag_type not in define_flag: raise ValueError('Unknown flag_type %s' % param_spec.flag_type) else: define_flag[param_spec.flag_type](name, param_spec.default_value, help=param_spec.description, **param_spec.kwargs)
Example #2
Source File: compute_bleu.py From models with Apache License 2.0 | 7 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #3
Source File: _misc.py From ml-on-gcp with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #4
Source File: compute_bleu.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #5
Source File: _misc.py From ml-on-gcp with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #6
Source File: config.py From trax with Apache License 2.0 | 6 votes |
def config_with_absl(self): # Run this before calling `app.run(main)` etc import absl.flags as absl_FLAGS from absl import app, flags as absl_flags self.use_absl = True self.absl_flags = absl_flags absl_defs = { bool: absl_flags.DEFINE_bool, int: absl_flags.DEFINE_integer, str: absl_flags.DEFINE_string, 'enum': absl_flags.DEFINE_enum } for name, val in self.values.items(): flag_type, meta_args, meta_kwargs = self.meta[name] absl_defs[flag_type](name, val, *meta_args, **meta_kwargs) app.call_after_init(lambda: self.complete_absl_config(absl_flags))
Example #7
Source File: _misc.py From nsfw with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #8
Source File: _misc.py From models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #9
Source File: flags_helpxml_test.py From abseil-py with Apache License 2.0 | 6 votes |
def test_flag_help_in_xml_enum(self): flags.DEFINE_enum('cc_version', 'stable', ['stable', 'experimental'], 'Compiler version to use.', flag_values=self.fv) expected_output = ( '<flag>\n' ' <file>tool</file>\n' ' <name>cc_version</name>\n' ' <meaning><stable|experimental>: ' 'Compiler version to use.</meaning>\n' ' <default>stable</default>\n' ' <current>stable</current>\n' ' <type>string enum</type>\n' ' <enum_value>stable</enum_value>\n' ' <enum_value>experimental</enum_value>\n' '</flag>\n') self._check_flag_help_in_xml('cc_version', 'tool', expected_output)
Example #10
Source File: argparse_flags_test.py From abseil-py with Apache License 2.0 | 6 votes |
def setUp(self): self._absl_flags = flags.FlagValues() flags.DEFINE_bool( 'absl_bool', None, 'help for --absl_bool.', short_name='b', flag_values=self._absl_flags) # Add a boolean flag that starts with "no", to verify it can correctly # handle the "no" prefixes in boolean flags. flags.DEFINE_bool( 'notice', None, 'help for --notice.', flag_values=self._absl_flags) flags.DEFINE_string( 'absl_string', 'default', 'help for --absl_string=%.', short_name='s', flag_values=self._absl_flags) flags.DEFINE_integer( 'absl_integer', 1, 'help for --absl_integer.', flag_values=self._absl_flags) flags.DEFINE_float( 'absl_float', 1, 'help for --absl_integer.', flag_values=self._absl_flags) flags.DEFINE_enum( 'absl_enum', 'apple', ['apple', 'orange'], 'help for --absl_enum.', flag_values=self._absl_flags)
Example #11
Source File: _misc.py From models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #12
Source File: compute_bleu.py From models with Apache License 2.0 | 6 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #13
Source File: _misc.py From models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #14
Source File: _misc.py From models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #15
Source File: compute_bleu.py From models with Apache License 2.0 | 6 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #16
Source File: _misc.py From models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #17
Source File: _misc.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #18
Source File: movielens_main.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def define_movie_flags(): """Define flags for movie dataset training.""" wide_deep_run_loop.define_wide_deep_flags() flags.DEFINE_enum( name="dataset", default=movielens.ML_1M, enum_values=movielens.DATASETS, case_sensitive=False, help=flags_core.help_wrap("Dataset to be trained and evaluated.")) flags.adopt_module_key_flags(wide_deep_run_loop) flags_core.set_defaults(data_dir="/tmp/movielens-data/", model_dir='/tmp/movie_model', model_type="deep", train_epochs=50, epochs_between_evals=5, inter_op_parallelism_threads=0, intra_op_parallelism_threads=0, batch_size=256) @flags.validator("stop_threshold", message="stop_threshold not supported for movielens model") def _no_stop(stop_threshold): return stop_threshold is None
Example #19
Source File: wide_deep_run_loop.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def define_wide_deep_flags(): """Add supervised learning flags, as well as wide-deep model type.""" flags_core.define_base(clean=True, train_epochs=True, epochs_between_evals=True) flags_core.define_benchmark() flags_core.define_performance( num_parallel_calls=False, inter_op=True, intra_op=True, synthetic_data=False, max_train_steps=False, dtype=False, all_reduce_alg=False) flags.adopt_module_key_flags(flags_core) flags.DEFINE_enum( name="model_type", short_name="mt", default="wide_deep", enum_values=['wide', 'deep', 'wide_deep'], help="Select model topology.") flags.DEFINE_boolean( name="download_if_missing", default=True, help=flags_core.help_wrap( "Download data to data_dir if it is not already present."))
Example #20
Source File: compute_bleu.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 6 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #21
Source File: flags.py From dlcookbook-dlbs with Apache License 2.0 | 6 votes |
def define_flags(): """Define a command line flag for each ParamSpec in flags.param_specs.""" define_flag = { 'boolean': absl_flags.DEFINE_boolean, 'float': absl_flags.DEFINE_float, 'integer': absl_flags.DEFINE_integer, 'string': absl_flags.DEFINE_string, 'enum': absl_flags.DEFINE_enum, 'list': absl_flags.DEFINE_list } for name, param_spec in six.iteritems(param_specs): if param_spec.flag_type not in define_flag: raise ValueError('Unknown flag_type %s' % param_spec.flag_type) else: define_flag[param_spec.flag_type](name, param_spec.default_value, help=param_spec.description, **param_spec.kwargs)
Example #22
Source File: movielens_main.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def define_movie_flags(): """Define flags for movie dataset training.""" wide_deep_run_loop.define_wide_deep_flags() flags.DEFINE_enum( name="dataset", default=movielens.ML_1M, enum_values=movielens.DATASETS, case_sensitive=False, help=flags_core.help_wrap("Dataset to be trained and evaluated.")) flags.adopt_module_key_flags(wide_deep_run_loop) flags_core.set_defaults(data_dir="/tmp/movielens-data/", model_dir='/tmp/movie_model', model_type="deep", train_epochs=50, epochs_between_evals=5, inter_op_parallelism_threads=0, intra_op_parallelism_threads=0, batch_size=256) @flags.validator("stop_threshold", message="stop_threshold not supported for movielens model") def _no_stop(stop_threshold): return stop_threshold is None
Example #23
Source File: wide_deep_run_loop.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def define_wide_deep_flags(): """Add supervised learning flags, as well as wide-deep model type.""" flags_core.define_base() flags_core.define_benchmark() flags_core.define_performance( num_parallel_calls=False, inter_op=True, intra_op=True, synthetic_data=False, max_train_steps=False, dtype=False, all_reduce_alg=False) flags.adopt_module_key_flags(flags_core) flags.DEFINE_enum( name="model_type", short_name="mt", default="wide_deep", enum_values=['wide', 'deep', 'wide_deep'], help="Select model topology.") flags.DEFINE_boolean( name="download_if_missing", default=True, help=flags_core.help_wrap( "Download data to data_dir if it is not already present."))
Example #24
Source File: _misc.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #25
Source File: compute_bleu.py From g-tensorflow-models with Apache License 2.0 | 6 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #26
Source File: _misc.py From models with Apache License 2.0 | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags
Example #27
Source File: compute_bleu.py From models with Apache License 2.0 | 6 votes |
def define_compute_bleu_flags(): """Add flags for computing BLEU score.""" flags.DEFINE_string( name="translation", default=None, help=flags_core.help_wrap("File containing translated text.")) flags.mark_flag_as_required("translation") flags.DEFINE_string( name="reference", default=None, help=flags_core.help_wrap("File containing reference translation.")) flags.mark_flag_as_required("reference") flags.DEFINE_enum( name="bleu_variant", short_name="bv", default="both", enum_values=["both", "uncased", "cased"], case_sensitive=False, help=flags_core.help_wrap( "Specify one or more BLEU variants to calculate. Variants: \"cased\"" ", \"uncased\", or \"both\"."))
Example #28
Source File: movielens_main.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def define_movie_flags(): """Define flags for movie dataset training.""" wide_deep_run_loop.define_wide_deep_flags() flags.DEFINE_enum( name="dataset", default=movielens.ML_1M, enum_values=movielens.DATASETS, case_sensitive=False, help=flags_core.help_wrap("Dataset to be trained and evaluated.")) flags.adopt_module_key_flags(wide_deep_run_loop) flags_core.set_defaults(data_dir="/tmp/movielens-data/", model_dir='/tmp/movie_model', model_type="deep", train_epochs=50, epochs_between_evals=5, inter_op_parallelism_threads=0, intra_op_parallelism_threads=0, batch_size=256) @flags.validator("stop_threshold", message="stop_threshold not supported for movielens model") def _no_stop(stop_threshold): return stop_threshold is None
Example #29
Source File: wide_deep_run_loop.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def define_wide_deep_flags(): """Add supervised learning flags, as well as wide-deep model type.""" flags_core.define_base() flags_core.define_benchmark() flags_core.define_performance( num_parallel_calls=False, inter_op=True, intra_op=True, synthetic_data=False, max_train_steps=False, dtype=False, all_reduce_alg=False) flags.adopt_module_key_flags(flags_core) flags.DEFINE_enum( name="model_type", short_name="mt", default="wide_deep", enum_values=['wide', 'deep', 'wide_deep'], help="Select model topology.") flags.DEFINE_boolean( name="download_if_missing", default=True, help=flags_core.help_wrap( "Download data to data_dir if it is not already present."))
Example #30
Source File: _misc.py From multilabel-image-classification-tensorflow with MIT License | 6 votes |
def define_image(data_format=True): """Register image specific flags. Args: data_format: Create a flag to specify image axis convention. Returns: A list of flags for core.py to marks as key flags. """ key_flags = [] if data_format: flags.DEFINE_enum( name="data_format", short_name="df", default=None, enum_values=["channels_first", "channels_last"], help=help_wrap( "A flag to override the data format used in the model. " "channels_first provides a performance boost on GPU but is not " "always compatible with CPU. If left unspecified, the data format " "will be chosen automatically based on whether TensorFlow was " "built for CPU or GPU.")) key_flags.append("data_format") return key_flags