yolo3 pb或者各种pb模型转换tflite,并量化

#建议使用ubuntu系统,tf好像在windows缺失tflite功能
#依赖:tansoeflow-gpu>=1.14.0(我的是1.14.0)
import tensorflow as tf
#获取需要转换模型路径
path="/home/hanqing/models-master/research/object_detection/mode1/saved_model.pb"        #pb文件位置和文件名
#输入模型变量名
input_arrays=["input_1_1"]               #模型文件的输入节点名称
#输出变量名
output_arrays=["conv2d_59_1/BiasAdd","conv2d_67_1/BiasAdd","conv2d_75_1/BiasAdd"]            #模型文件的输出节点名称
#输入变量-数据的数量/图像大小/通道(保持跟训练模型时一致就好)
input_shapes={"input_1_1":[1,416,416,3]}
#从模型创建TFLiteConverter类
converter = tf.lite.TFLiteConverter.from_frozen_graph(path, input_arrays, output_arrays,input_shapes)
#将转换器的训练后是否量化设置为 true
converter.post_training_quantize=True
#允许自定义操作(之转换格式,就注释上面“converter.post_training_quantize=True”,打开“converter.allow_custom_ops=True”)
# converter.allow_custom_ops=True
#基于实例变量转换TensorFlow GraphDef(转换)
tflite_model=converter.convert()
#保存tflite地址
open("/home/hanqing/models-master/research/object_detection/mode1/yolo3_pb.tflite", "wb").write(tflite_model)

已经实测转换完成,转载请代连接,测试不易,有问题备注

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

读书小孩

您的打赏将是我前行的动力源

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值