python - 如何测试加载 tflite 模型并在一张图像上进行测试
问题描述
我已经使用 tflite 模型制作器训练了跌倒和非跌倒人员检测模型,并且我在训练时对其进行了测试,但我想通过加载 tflite 文件并仅提供一张图像来进行测试。
解决方案
此页面包含有关如何使用 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
您的输入图像。
推荐阅读
- c - 构建 cc_library 时如何在 bazel 中移动文件?
- excel - 如何将一个工作表中的列粘贴到另一工作表下方?两列的长度相等但未知
- haskell - 具有各种标志的堆栈缓存构建
- c++ - 在不使用全局变量的情况下从主范围更改函数中的局部变量
- javascript - VueJS:`v-for`不渲染元素
- c# - 实体框架返回错误 - 存储数据提供程序返回的数据读取器没有足够的列
- python - 使用 QMessageBox 时无法使用 QThread 设置父错误
- jenkins - 用詹金斯构建apk?错误:存档工件
- fpga - vivado:未使用的顺序元素已删除
- javascript - 切换按钮的背景颜色不起作用