【发布时间】:2021-11-18 03:11:33
【问题描述】:
我已经使用 TF2 API 训练了一个 EfficientDet-d0 模型,以便检测自定义图像。这工作得很好。已保存检查点、pipeline.config 和 save_model.pb 文件,并且可以使用这些文件重新加载模型。问题是我无法将此模型转换为 tflite 格式以便在 RaspberryPi 上使用它。尝试使用 Google Colab 笔记本中的 TF 文档 (https://www.tensorflow.org/lite/guide/inference#load_and_run_a_model_in_python) 进行转换:https://colab.research.google.com/drive/1cnJF85aPz5VMyEJ0gzsdB3zjvXaRCG_r?usp=sharing
转换本身似乎正在工作,但是当我设置解释器时出现问题,因为所有值都是 0 并且输入形状是 [1 1 1 3]:
interpreter = tf.lite.Interpreter(TFLITE_FILE_PATH)
print(interpreter.get_input_details())
[{'name': 'serving_default_input_tensor:0', 'index': 0, 'shape': array([1, 1, 1, 3], dtype=int32), 'shape_signature': array([ 1 , -1, -1, 3], dtype=int32), 'dtype':
, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([ ], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_shape = input_details[0]['shape']
print(input_shape)
[1 1 1 3]
当我尝试设置张量时,出现以下错误
input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32)
interpreter.set_tensor(input_details[0]['index'], input_data)
ValueError:无法设置张量:得到 FLOAT32 类型的值,但输入 0 的预期类型为 UINT8,名称:serving_default_input_tensor:0
任何人都知道我如何正确转换模型或我做错了什么?非常感谢!
【问题讨论】:
-
你可以尝试在tflite转换时将输入形状设置为固定值吗?
-
嗨!您是否检查过类似的错误堆栈跟踪问题。 stackoverflow.com/a/59855962/11530462
标签: python tensorflow object-detection object-detection-api