https://github.com/tensorflow/models/issues/8148#issuecomment-641028423
想生成tflite格式的模型,用于安卓端做推理的时候,不知道toco需要指定哪些参数,所以另写一篇文章放在这里。
usage下列出了所有参数,后面对参数含义做了详细说明。usage中列有很多参数,--***是我们输入命令行时的参数,以下为例:
--output_file=""
command:
# tflite_convert -husage: tflite_convert [-h] --output_file OUTPUT_FILE(--graph_def_file GRAPH_DEF_FILE | --saved_model_dir SAVED_MODEL_DIR | --keras_model_file KERAS_MODEL_FILE)[--output_format {TFLITE,GRAPHVIZ_DOT}][--inference_type {FLOAT,QUANTIZED_UINT8}][--inference_input_type {FLOAT,QUANTIZED_UINT8}][--input_arrays INPUT_ARRAYS][--input_shapes INPUT_SHAPES][--output_arrays OUTPUT_ARRAYS][--saved_model_tag_set SAVED_MODEL_TAG_SET][--saved_model_signature_key SAVED_MODEL_SIGNATURE_KEY][--std_dev_values STD_DEV_VALUES][--mean_values MEAN_VALUES][--default_ranges_min DEFAULT_RANGES_MIN][--default_ranges_max DEFAULT_RANGES_MAX][--post_training_quantize] [--drop_control_dependency][--reorder_across_fake_quant][--change_concat_input_ranges {TRUE,FALSE}][--allow_custom_ops][--converter_mode {DEFAULT,TOCO_FLEX,TOCO_FLEX_ALL}][--dump_graphviz_dir DUMP_GRAPHVIZ_DIR][--dump_graphviz_video]Command line tool to run TensorFlow Lite Optimizing Converter (TOCO).optional arguments:-h, --help show this help message and exit--output_file OUTPUT_FILEFull filepath of the output file.--graph_def_file GRAPH_DEF_FILEFull filepath of file containing frozen TensorFlowGraphDef.--saved_model_dir SAVED_MODEL_DIRFull filepath of directory containing the SavedModel.--keras_model_file KERAS_MODEL_FILEFull filepath of HDF5 file containing tf.Keras model.--output_format {TFLITE,GRAPHVIZ_DOT}Output file format.--inference_type {FLOAT,QUANTIZED_UINT8}Target data type of real-number arrays in the outputfile.--inference_input_type {FLOAT,QUANTIZED_UINT8}Target data type of real-number input arrays. Allowsfor a different type for input arrays in the case ofquantization.--input_arrays INPUT_ARRAYSNames of the input arrays, comma-separated.--input_shapes INPUT_SHAPESShapes corresponding to --input_arrays, colon-separated.--output_arrays OUTPUT_ARRAYSNames of the output arrays, comma-separated.--saved_model_tag_set SAVED_MODEL_TAG_SETComma-separated set of tags identifying theMetaGraphDef within the SavedModel to analyze. Alltags must be present. (default "serve")--saved_model_signature_key SAVED_MODEL_SIGNATURE_KEYKey identifying the SignatureDef containing inputs andoutputs. (default DEFAULT_SERVING_SIGNATURE_DEF_KEY)--std_dev_values STD_DEV_VALUESStandard deviation of training data for each inputtensor, comma-separated floats. Used for quantizedinput tensors. (default None)--mean_values MEAN_VALUESMean of training data for each input tensor, comma-separated floats. Used for quantized input tensors.(default None)--default_ranges_min DEFAULT_RANGES_MINDefault value for min bound of min/max range valuesused for all arrays without a specified range,Intended for experimenting with quantization via"dummy quantization". (default None)--default_ranges_max DEFAULT_RANGES_MAXDefault value for max bound of min/max range valuesused for all arrays without a specified range,Intended for experimenting with quantization via"dummy quantization". (default None)--post_training_quantizeBoolean indicating whether to quantize the weights ofthe converted float model. Model size will be reducedand there will be latency improvements (at the cost ofaccuracy). (default False)--drop_control_dependencyBoolean indicating whether to drop controldependencies silently. This is due to TensorFlow notsupporting control dependencies. (default True)--reorder_across_fake_quantBoolean indicating whether to reorder FakeQuant nodesin unexpected locations. Used when the location of theFakeQuant nodes is preventing graph transformationsnecessary to convert the graph. Results in a graphthat differs from the quantized training graph,potentially causing differing arithmetic behavior.(default False)--change_concat_input_ranges {TRUE,FALSE}Boolean to change behavior of min/max ranges forinputs and outputs of the concat operator forquantized models. Changes the ranges of concatoperator overlap when true. (default False)--allow_custom_ops Boolean indicating whether to allow custom operations.When false any unknown operation is an error. Whentrue, custom ops are created for any op that isunknown. The developer will need to provide these tothe TensorFlow Lite runtime with a custom resolver.(default False)--converter_mode {DEFAULT,TOCO_FLEX,TOCO_FLEX_ALL}Experimental flag, subject to change. ConverterModeindicating which converter to use. (defaultConverterMode.DEFAULT)--dump_graphviz_dir DUMP_GRAPHVIZ_DIRFull filepath of folder to dump the graphs at variousstages of processing GraphViz .dot files. Preferredover --output_format=GRAPHVIZ_DOT in order to keep therequirements of the output file.--dump_graphviz_videoBoolean indicating whether to dump the graph afterevery graph transformation