首页 文章

TFLite:无法在自定义数据集上使用MobilenetV2获取推理

提问于
浏览
0

我已经关注了this链接,并通过对我的自定义数据集进行微调,成功为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.

2 回答

  • 0

    你有没有尝试过这个论点--input_array = Predictions . 您可以尝试使用量化模型

  • 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))
    

相关问题