# 使用离线转换工具 (CLI) 进行转换

Source: [https://docs.qualcomm.com/doc/80-70014-54Y/topic/convert-using-offline-converter-tool-cli.html](https://docs.qualcomm.com/doc/80-70014-54Y/topic/convert-using-offline-converter-tool-cli.html)

TensorFlow Lite 转换工具 tflite\_convert 可离线使用，包含在 TensorFlow pip 包中，适用于 TensorFlow 2.x 及以上版本。

Tflite\_convert 工具在 CLI 中接受以下输入：

    tflite_convert --help
    
    optional arguments:
      -h, --help            show this help message and exit
      --output_file OUTPUT_FILE
                            Full filepath of the output file.
      --saved_model_dir SAVED_MODEL_DIR
                            Full path of the directory containing the SavedModel.
      --keras_model_file KERAS_MODEL_FILE
                            Full filepath of HDF5 file containing tf.Keras model.
      --saved_model_tag_set SAVED_MODEL_TAG_SET
                            Comma-separated set of tags identifying the MetaGraphDef within the SavedModel to analyze. All tags must be present. To pass in an empty
                            tag set, pass in "". (default "serve")
      --saved_model_signature_key SAVED_MODEL_SIGNATURE_KEY
                            Key identifying the SignatureDef containing inputs and outputs. (default DEFAULT_SERVING_SIGNATURE_DEF_KEY)
      --enable_v1_converter
                            Enables the TensorFlow V1 converter in 2.0
    Copy to clipboard

## 转换 SavedModel

要使用 tflite\_convert 工具转换以 saved\_model 格式保存的典型 TensorFlow 模型，运行以下命令：

    tflite_convert \    --saved_model_dir=/tmp/mobilenet_saved_model \    --output_file=/tmp/mobilenet.tflite \  --saved_model_tag_set=serve \
             --saved_model_signature_key=”serving_default”
    Copy to clipboard

## 转换 Keras H5 模型

要使用 tflite\_convert 工具转换 Keras 模型，运行以下命令：

    tflite_convert \
      --keras_model_file=/tmp/mobilenet_keras_model.h5 \
      --output_file=/tmp/mobilenet.tflite
    Copy to clipboard

Note: tflite\_convert 工具仅用于基本用途。建议使用 Python API 进行训练后整数量化。

**Parent Topic:** [将 TensorFlow 或 Keras 模型转换为 TensorFlow Lite 格式](https://docs.qualcomm.com/doc/80-70014-54Y/topic/convert-a-tensorflow-or-keras-model-to-tensorflow-lite-format.html)

Last Published: Aug 06, 2024

[Previous Topic
使用 Python API 进行转换和量化](https://docs.qualcomm.com/bundle/publicresource/80-70014-54Y/topics/convert-and-quantize-using-python-apis.md) [Next Topic
运行推理](https://docs.qualcomm.com/bundle/publicresource/80-70014-54Y/topics/run-inference.md)