【发布时间】:2020-10-27 17:14:45
【问题描述】:
我试图弄清楚如何从 tensorflow 模型中保存预测的掩码(输出),该模型已在我的 PC 上转换为 tf.lite 模型。关于如何将其可视化或将预测的蒙版保存为 .png 图像的任何提示或想法。我尝试使用来自https://www.tensorflow.org/lite/guide/inference#load_and_run_a_model_in_python 的 tensorflow Lite 干扰但没有成功。
现在输出如下:
[ 1 512 512 3]
[[[[9.7955531e-01 2.0444747e-02]
[9.9987805e-01 1.2197520e-04]
[9.9978799e-01 2.1196880e-04]
.......
.......
[9.9997246e-01 2.7536058e-05]
[9.9997437e-01 2.5645388e-05]
[1.9125430e-03 9.9808747e-01]]]]
非常感谢任何帮助。 非常感谢
## Load the TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="tflite_model.tflite")
print(interpreter.get_input_details())
print(interpreter.get_output_details())
print(interpreter.get_tensor_details())
interpreter.allocate_tensors()
## Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
## Test the model on input data.
input_shape = input_details[0]['shape']
print(input_shape)
## Use same image as Keras model
input_data = np.array(Xall, dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
## The function `get_tensor()` returns a copy of the tensor data.
## Use `tensor()` in order to get a pointer to the tensor.
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)
output_data.shape
【问题讨论】:
标签: python-3.x tensorflow2.0 tensorflow-lite