【问题标题】:Unexpected failure when preparing tensor allocations准备张量分配时意外失败
【发布时间】:2019-04-22 12:05:51
【问题描述】:

我正在使用 tflite 进行语义分割。我有一个模型训练来从背景中分割对象,这个模型是在 deeplab 上训练的。

我已使用以下代码将此模型(冻结推理图)转换为 tflite 格式:

tflite_convert \
  --output_file=test.lite \
  --graph_def_file=frozen_inference_graph.pb \
  --input_arrays=ImageTensor \
  --output_arrays=SemanticPredictions \
  --input_shapes=1,600,450,3 \
  --inference_input_type=QUANTIZED_UINT8 \
  --inference_type=FLOAT \
  --mean_values=128 \
  --std_dev_values=128 

模型在 android 上加载,但是当我尝试运行推理时,它给了我这个错误:

原因:java.lang.IllegalStateException:内部错误:意外 准备张量分配时失败: third_party/tensorflow/lite/kernels/unpack.cc:54 NumDimensions(input)

1 不正确。节点号 4 (UNPACK) 准备失败。

如何解决这个错误?

【问题讨论】:

  • 可能输入的形状不对。您可以发布用于在 Android 中加载和重塑数据的代码。
  • 我在 android studio 中将图像大小调整为 513X385,并在这个调整大小的图像上运行推理。我试着把 --input_shapes=1,450,600,3 \, --input_shapes=1,513,385,3 \ 它确实消除了这两种情况下的错误,但它似乎没有产生任何输出。相反,tfmobile 模型在 android 上运行良好
  • @ShubhamPanchal 我找到了问题的根源 (stackoverflow.com/questions/55808705/…) 但我不知道解决方案你介意看看上面发布的链接吗?

标签: android tensorflow machine-learning computer-vision artificial-intelligence


【解决方案1】:

它适用于以下命令:

bazel-bin/tensorflow/lite/toco/toco \
  --input_file=deeplabv3_mnv2_pascal_tain.pb \
  --output_file=test.tflite \
  --inference_input_type=QUANTIZED_UINT8  \
  --inference_type=FLOAT \
  --input_arrays=ImageTensor  \
  --output_arrays=SemanticPredictions  \
  --input_shapes=1,513,513,3 \
  --mean_values=128 \
  --std_dev_values=128

当我从源代码安装 tensorflow 时它起作用了。为了从我使用的源安装 tensorflow (link)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多