【发布时间】:2020-07-07 21:09:55
【问题描述】:
我是这一切的新手,我需要一些帮助来使用自定义 tflite yolov3 微型模型运行推理。 我得到的错误是:
File "/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/interpreter.py", line 524, in invoke
self._interpreter.Invoke()
RuntimeError: tensorflow/lite/kernels/reshape.cc:55 stretch_dim != -1 (0 != -1)Node number 35 (RESHAPE) failed to prepare.
为了到达这里我做了什么:
- 使用这个项目训练了一个自定义的 yolov3 微型物体检测模型,只检测 1 个类别 https://github.com/pythonlessons/TensorFlow-2.x-YOLOv3.git
- 使用的默认超参数: https://github.com/pythonlessons/TensorFlow-2.x-YOLOv3/blob/master/yolov3/configs.py
- 每晚使用 tf
- 型号在这里: https://github.com/vladimirhorvat/y/blob/master/app/src/main/assets/converted_model.tflite
训练模型后,我通过运行推理测试了 SavedModel,它工作正常。 将 SavedModel 转换为 tflite,使用以下代码对其进行推理,并收到标题的错误:
interpreter = tf.lite.Interpreter(model_path="converted_model.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
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()
(这段代码来自这里,顺便说一句 https://www.tensorflow.org/lite/guide/inference#load_and_run_a_model_in_python)
节点 35 的数据:
type: Reshape
location: 35
inputs
data: name: functional_1/tf_op_layer_Tile_3/Tile_3;StatefulPartitionedCall/functional_1/tf_op_layer_Tile_3/Tile_3
shape: name: functional_1/tf_op_layer_strided_slice_6/strided_slice_6;StatefulPartitionedCall/functional_1/tf_op_layer_strided_slice_6/strided_slice_6
outputs
reshaped: name: functional_1/tf_op_layer_strided_slice_16/strided_slice_16;StatefulPartitionedCall/functional_1/tf_op_layer_strided_slice_16/strided_slice_16
请帮忙。我没有想法。
【问题讨论】:
-
我在 TF 2.3 中开始遇到这个问题。现在我只使用 TF 2.3 进行训练,我回滚到 TF 2.2 进行 tflite 导出。
标签: python tensorflow tensorflow2.0 yolo