tensorflow模型转为tflite

tensorflow模型转换主要分为:步骤1、步骤2。步骤1最为关键。

1、ckpt转为pb模型

主要步骤参考MobileFaceNet模型转换问题,其它模型转换也是按此步骤,注意输入、输出节点的选择。
转换过程中出现以下错误,应该是batch_norm_params参数设置的问题。应将is_training设置为False,将trainable设置为False,则不会出现以下错误。若仍然报错不支持相关操作,可能是版本原因。之前在tensorflow1.5上进行转换,报错。但更换为tensorflow1.14之后,不再报错。

Some of the operators in the model are not supported by the standard TensorFlow Lite runtime. If those are native TensorFlow operators, you might be able to use the extended runtime by passing --enable_select_tf_ops, or by setting target_ops=TFLITE_BUILTINS,SELECT_TF_OPS when calling tf.lite.TFLiteConverter(). Otherwise, if you have a custom implementation for them you can disable this error with --allow_custom_ops, or by setting allow_custom_ops=True when calling tf.lite.TFLiteConverter(). Here is a list of builtin operators you are using: ADD, AVERAGE_POOL_2D, CONCATENATION, CONV_2D, DEPTHWISE_CONV_2D, FULLY_CONNECTED, MUL, PACK, RELU6, RESHAPE, RSQRT, SHAPE, STRIDED_SLICE. Here is a list of operators for which you will need custom implementations: BatchNormalization, Merge, Switch.

2、pb模型转TFlite模型

主要使用tflite_convert命令,如果步骤1是正确的,步骤2不会报错。所以出现报错,应该仔细检查步骤1.

tflite_convert --output_file PFLD.tflite --graph_def_file new-frozen_model.pb  --input_arrays "image_batch" --input_shapes "1,112,112,3" --output_arrays pfld_inference/fc/BiasAdd --output_format TFLITE

你可能感兴趣的:(TensorFlow)