tensorflow模型转为tflite

本文详细介绍了TensorFlow模型从ckpt到pb,再到TFlite的转换流程。特别关注输入输出节点选择、batch_norm_params参数调整及版本兼容性问题。通过案例解析,帮助读者避免常见错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值