问题描述
我使用以下命令将没有Keras的TensorFlow 1模型转换为TFLite:
converter = tf.lite.TFLiteConverter.from_session(sess,input_tensors=[my_input_tensor],output_tensors=[my_output_tensor])
tflite_model = converter.convert()
成功保存了输出,但是使用模型进行预测时,输出与常规TensorFlow模型的输出完全不同。这是我在Python中运行推理的方式:
interpreter = tf.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
print("input details",input_details)
print("output details",output_details)
interpreter.set_tensor(input_details[0]['index'],input_array.reshape(input_shape))
interpreter.invoke()
output_buff = interpreter.get_tensor(output_details[0]['index']).squeeze()
控制台:
input details [{'name': 'input_batch','index': 0,'shape': array([ 1,606,414,1],dtype=int32),'shape_signature': array([ 1,'dtype': <class 'numpy.float32'>,'quantization': (0.0,0),'quantization_parameters': {'scales': array([],dtype=float32),'zero_points': array([],'quantized_dimension': 0},'sparsity_parameters': {}}]
output details [{'name': 'Mul','index': 1,505,324,'sparsity_parameters': {}}]
在解决此问题方面,我将不胜感激。
[更新]:我也尝试过先将图形冻结到pb文件中的方法,但是得到的结果相同。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)