【问题标题】:Output predicted image Tensorflow Lite输出预测图像 Tensorflow Lite
【发布时间】: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


    【解决方案1】:

    这取决于您的模型输出的含义。然后,使用cv2PIL 等图片库来绘制蒙版。

    例如第一行:

      9.7955531e-01 2.0444747e-02
    

    你需要弄清楚它们对应的是什么。由于信息有限,很难从上下文中猜测。

    【讨论】:

    • 谢谢,我是新手,只是对行的解释使它更清楚。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2019-04-08
    • 2019-07-22
    • 1970-01-01
    • 2017-02-21
    • 2019-03-31
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    相关资源
    最近更新 更多