【问题标题】:How to test load tflite model and test on one image如何测试加载 tflite 模型并在一张图像上进行测试
【发布时间】:2021-09-28 05:53:47
【问题描述】:

我已经使用 tflite 模型生成器训练了跌倒和不跌倒的人检测模型,并且我在训练时对其进行了测试,但我想通过加载 tflite 文件并仅提供一张图像来进行测试。

【问题讨论】:

    标签: python tensorflow tensorflow-lite


    【解决方案1】:

    This page 有关于如何使用 python 加载 TFLite 模型的说明:

    import numpy as np
    import tensorflow as tf
    
    # Load the TFLite model and allocate tensors.
    interpreter = tf.lite.Interpreter(model_path="converted_model.tflite")
    interpreter.allocate_tensors()
    
    # Get input and output tensors.
    input_details = interpreter.get_input_details()
    output_details = interpreter.get_output_details()
    
    # Test the model on random input data.
    input_shape = input_details[0]['shape']
    input_data = np.array(np.random.random_sample(input_shape), 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)
    

    用您的输入图像替换input_data

    【讨论】:

      猜你喜欢
      • 2019-05-11
      • 1970-01-01
      • 2021-08-15
      • 2021-11-03
      • 1970-01-01
      • 2017-08-06
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多