我正在使用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
模型在安卓上可以加载,但是当我尝试运行推理时,它给出了以下错误:
由以下原因引起:java.lang.IllegalStateException: 内部错误:在准备张量分配时发生意外错误:third_party/tensorflow/lite/kernels/unpack.cc:54 NumDimensions(input)
1 was not true.Node number 4 (UNPACK) failed to prepare.
我该如何解决这个错误?
回答:
以下命令可以正常工作:
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,我使用了(链接)