先将tensorflow2.4cpkt转为.pb模型。再将.pb模型转为.tflite时报错
File "D:\Program Files\Python\Python37\lib\site-packages\tensorflow\lite\python\convert.py", line 216, in toco_convert_protos
raise ConverterError(str(e))
tensorflow.lite.python.convert.ConverterError: <unknown>:0: error: loc("bidirectional_rnn/bw/bw/while"): 'tf.WhileRegion' op body result type tensor<1x1x256xf32> is incompatible with result type tensor<0x1x256xf32> at index 7
下面是我.pb转tflite的代码
import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
# 把pb文件路径改成自己的pb文件路径即可
path = "../model/HTOCR.pb"
# 如果是不知道自己的模型的输入输出节点,建议用tensorboard做可视化查看计算图,计算图里有输入输出的节点名称
inputs = ["Placeholder","Placeholder_4","is_train"]
outputs = ["CTCGreedyDecoder","transpose"]
input_tensor_shape = {'Placeholder': [1, 616, 32],'Placeholder_4':[1],'is_train':[1]}
# 转换pb模型到tflite模型
converter = tf.lite.TFLiteConverter.from_frozen_graph(path, inputs, outputs,input_tensor_shape)
# converter.post_training_quantize = True
tflite_model = converter.convert()
open("../model/HTOCR.tflite", "wb").write(tflite_model)
相似问题