0

我已经按照这个链接并通过微调我的自定义数据集成功地为 MoiblenetV2_1.4_224 创建了冻结图。然后,我按照tensorflow-for-poets:tflite使用以下命令使用 toco 创建 tflite 图。

IMAGE_SIZE=224
toco \
--input_file=frozen_mobilenet_v2.pb \
--output_file=optimized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=10,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_array=input \
--output_array=MobilenetV2/Predictions/Softmax \
--inference_type=FLOAT \
--input_data_type=FLOAT

lite 图已成功创建,但在推理期间,在运行 tflite Interpretor 时出现以下错误。因此,我没有得到任何推论。

Input error: Failed to get input dimensions. 0-th input should have 6021120 bytes, but found 602112 bytes.
4

2 回答 2

0

输入错误:无法获取输入尺寸。

命令行标志应该是--input_arrays而不是--input_array。(复数而不是单数)。同上--output_arrays而不是--output_array. 那应该可以解决您的错误。所以命令应该是:

IMAGE_SIZE=224
toco \
--input_file=frozen_mobilenet_v2.pb \
--output_file=optimized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--input_shape=10,${IMAGE_SIZE},${IMAGE_SIZE},3 \
--input_arrays=input \
--output_arrays=MobilenetV2/Predictions/Softmax \
--inference_type=FLOAT \
--input_data_type=FLOAT

附加调试提示

为了将来参考,如果您的标志都正确,那么下一步将是检查您的输入和输出张量名称是否正确。您可以尝试在 Tensorboard 中可视化图形的输入和输出,或按如下方式转换为 pbtxt,然后将其读出:

import tensorflow as tf
path_to_pb = '...'
output_file = '...'
g = tf.GraphDef()
with open(path_to_pb, 'rb') as f:
  g.ParseFromString(f.read())
with open(output_file, 'w') as f:
  f.write(str(g))
于 2018-05-23T17:14:34.137 回答
0

您是否尝试过这个参数--input_array=Predictions。您可以尝试使用量化模型

于 2018-05-23T10:48:29.747 回答