in tfjs-converter/python/tensorflowjs/converters/converter.py [0:0]
def get_arg_parser():
"""
Create the argument parser for the converter binary.
"""
parser = argparse.ArgumentParser('TensorFlow.js model converters.')
parser.add_argument(
common.INPUT_PATH,
nargs='?',
type=str,
help='Path to the input file or directory. For input format "keras", '
'an HDF5 (.h5) file is expected. For input format "tensorflow", '
'a SavedModel directory, frozen model file, '
'or TF-Hub module is expected.')
parser.add_argument(
common.OUTPUT_PATH,
nargs='?',
type=str,
help='Path for all output artifacts.')
parser.add_argument(
'--%s' % common.INPUT_FORMAT,
type=str,
required=False,
default=common.TF_SAVED_MODEL,
choices=set([common.KERAS_MODEL, common.KERAS_SAVED_MODEL,
common.TF_SAVED_MODEL, common.TF_HUB_MODEL,
common.TFJS_LAYERS_MODEL, common.TF_FROZEN_MODEL]),
help='Input format. '
'For "keras", the input path can be one of the two following formats:\n'
' - A topology+weights combined HDF5 (e.g., generated with'
' `tf.keras.model.save_model()` method).\n'
' - A weights-only HDF5 (e.g., generated with Keras Model\'s '
' `save_weights()` method). \n'
'For "keras_saved_model", the input_path must point to a subfolder '
'under the saved model folder that is passed as the argument '
'to tf.contrib.save_model.save_keras_model(). '
'The subfolder is generated automatically by tensorflow when '
'saving keras model in the SavedModel format. It is usually named '
'as a Unix epoch time (e.g., 1542212752).\n'
'For "tf" formats, a SavedModel, frozen model, '
' or TF-Hub module is expected.')
parser.add_argument(
'--%s' % common.OUTPUT_FORMAT,
type=str,
required=False,
choices=set([common.KERAS_MODEL, common.KERAS_SAVED_MODEL,
common.TFJS_LAYERS_MODEL, common.TFJS_GRAPH_MODEL]),
help='Output format. Default: tfjs_graph_model.')
parser.add_argument(
'--%s' % common.SIGNATURE_NAME,
type=str,
default=None,
help='Signature of the SavedModel Graph or TF-Hub module to load. '
'Applicable only if input format is "tf_hub" or "tf_saved_model".')
parser.add_argument(
'--%s' % common.SAVED_MODEL_TAGS,
type=str,
default='serve',
help='Tags of the MetaGraphDef to load, in comma separated string '
'format. Defaults to "serve". Applicable only if input format is '
'"tf_saved_model".')
parser.add_argument(
'--%s' % common.QUANTIZATION_TYPE_FLOAT16,
type=str,
default=None,
const=True,
nargs='?',
help='Comma separated list of node names to apply float16 quantization. '
'You can also use wildcard symbol (*) to apply quantization to multiple '
'nodes (e.g., conv/*/weights). When the flag is provided without any '
'nodes the default behavior will match all nodes.')
parser.add_argument(
'--%s' % common.QUANTIZATION_TYPE_UINT8,
type=str,
default=None,
const=True,
nargs='?',
help='Comma separated list of node names to apply 1-byte affine '
'quantization. You can also use wildcard symbol (*) to apply '
'quantization to multiple nodes (e.g., conv/*/weights). When the flag is '
'provided without any nodes the default behavior will match all nodes.')
parser.add_argument(
'--%s' % common.QUANTIZATION_TYPE_UINT16,
type=str,
default=None,
const=True,
nargs='?',
help='Comma separated list of node names to apply 2-byte affine '
'quantization. You can also use wildcard symbol (*) to apply '
'quantization to multiple nodes (e.g., conv/*/weights). When the flag is '
'provided without any nodes the default behavior will match all nodes.')
parser.add_argument(
'--%s' % common.QUANTIZATION_BYTES,
type=int,
choices=set(quantization.QUANTIZATION_BYTES_TO_DTYPES.keys()),
help='(Deprecated) How many bytes to optionally quantize/compress the '
'weights to. 1- and 2-byte quantizaton is supported. The default '
'(unquantized) size is 4 bytes.')
parser.add_argument(
'--%s' % common.SPLIT_WEIGHTS_BY_LAYER,
action='store_true',
help='Applicable to keras input_format only: Whether the weights from '
'different layers are to be stored in separate weight groups, '
'corresponding to separate binary weight files. Default: False.')
parser.add_argument(
'--%s' % common.VERSION,
'-v',
dest='show_version',
action='store_true',
help='Show versions of tensorflowjs and its dependencies')
parser.add_argument(
'--%s' % common.SKIP_OP_CHECK,
action='store_true',
help='Skip op validation for TensorFlow model conversion.')
parser.add_argument(
'--%s' % common.STRIP_DEBUG_OPS,
type=bool,
default=True,
help='Strip debug ops (Print, Assert, CheckNumerics) from graph.')
parser.add_argument(
'--%s' % common.WEIGHT_SHARD_SIZE_BYTES,
type=int,
default=None,
help='Shard size (in bytes) of the weight files. Currently applicable '
'only when output_format is tfjs_layers_model or tfjs_graph_model.')
parser.add_argument(
'--output_node_names',
type=str,
help='The names of the output nodes, separated by commas. E.g., '
'"logits,activations". Applicable only if input format is '
'"tf_frozen_model".')
parser.add_argument(
'--%s' % common.CONTROL_FLOW_V2,
type=bool,
default=False,
help='Enable control flow v2 ops, this would improve inference '
'performance on models with branches or loops.')
parser.add_argument(
'--%s' % common.EXPERIMENTS,
type=bool,
default=False,
help='Enable experimental features, you should only enable this flag '
'when using Python3 and TensorFlow nightly build.')
parser.add_argument(
'--%s' % common.METADATA,
type=str,
help='Attach user defined metadata in format key:path/metadata.json '
'Separate multiple metadata files by comma.'
)
return parser