tf版本:1.12.0? gpu版本
import tensorflow as tf
path_to_frozen_graphdef_pb = '/***/****/frozen_eval_graph-245400-20000.pb' #模型路径
converter = tf.contrib.lite.TFLiteConverter.from_frozen_graph(path_to_frozen_graphdef_pb,
input_arrays=["Placeholder"],#模型输入节点的name
output_arrays=["head/reg13x13_output/BiasAdd","head/reg26x26/BiasAdd","head/reg52x52/BiasAdd"])#模型输出节点的name,我的是yolov3,所以有三个输出
converter.inference_type = tf.contrib.lite.constants.QUANTIZED_UINT8 #转成uint8格式
converter.quantized_input_stats = {"Placeholder": (0., 1.)} #改前边"Placeholder"为自己的name,后边(0., 1.)不用动
converter.allow_custom_ops = True
converter.default_ranges_stats = (0, 255) #不动
converter.post_training_quantize = True
tflite_model = converter.convert()
open("/****/eval_graph.tflite", "wb").write(tflite_model) #前边为要保存的.tflite路径
|