Tflite在Python解释器和i中提供的准确性/行为不同。

2024-10-02 22:27:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用训练和服务于实时移动对象检测器link文章定制了一个对象检测模型。在训练并将模型转换为tflite之后,我使用Python解释器测试模型,然后通过遵循github tflite iOS exmaple将其与iOS集成。该模型在python解释器上运行良好,但在iOS中通过检测错误的对象和较低的置信度分数显示出完全不同的行为。你知道吗

我试过几种型号,包括:

  1. ssd\u mobilenet\u v1\u量化\u coco
  2. ssd\u mobilenet\u v2\u量化\u coco

默认的tflite模型检测.tfliteprovided in iOS github exmaple可以在iOS和python解释器中工作,但自定义模型不能。你知道吗

python解释器代码供参考

import tensorflow as tf

# Load TFLite model and allocate tensors.
interpreter = tf.contrib.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 model on random input data.
input_shape = input_details[0]['shape']
# change the following line to feed into your own data.
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)

interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)

Tags: 对象模型inputoutputdatagetmodelrandom