Tensorflow lite Tensorflow 1 TFLite从\u会话和\u冻结\u图转换产生错误的输出

Tensorflow lite Tensorflow 1 TFLite从\u会话和\u冻结\u图转换产生错误的输出,tensorflow-lite,tensorflow1.15,Tensorflow Lite,Tensorflow1.15,我使用以下命令将不带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() 输出已成功保存,但使用模型进行预测时,输出与常规Tensor

我使用以下命令将不带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, 606, 414,   1], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
output details [{'name': 'Mul', 'index': 1, 'shape': array([  1, 505, 324,   1], dtype=int32), 'shape_signature': array([  1, 505, 324,   1], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
输入详细信息[{'name':'input_batch','index':0,'shape':数组([1606414,1],dtype=int32),'shape_签名]:数组([1606414,1],dtype=int32),'dtype':,'quantization':(0.0,0),'quantization_参数':{'scales':数组([],dtype=float32),'zero_points':数组([],dtype=int32),'quantized"量子化维:0},'sparsity_parameters':{}]
输出详细信息[{'name':'Mul','index':1,'shape':数组([1505,324,1],dtype=int32),'shape\u签名]:数组([1505,324,1],dtype=int32),'dtype':,'quantization':(0.0,0),'quantization\u参数':{'scales':数组([],dtype=float32),'zero\u点:数组([],dtype=int32),'quantized\u维度:'0},'sparity\u参数:{}]
输出可能是输入信号的副本,也可能是随机噪声

如果能帮我解决这个问题,我将不胜感激


[更新]:我也尝试了先将图形冻结到pb文件的方法,但得到了相同的结果。

您是否尝试过保存\u模型?试一下,然后你试过保存的模型吗?试着然后