首页 文章

无法测试和部署用于推理的deeplabv3-mobilenetv2 tensorflow-lite分段模型

提问于
浏览
2

我们尝试使用deeplabv3和mobilenetv2在android上运行语义分割模型 . 我们在bazel的帮助下使用TOCO和tflite_convert遵循官方tensorflow lite转换过程 . 源冻结图是从官方TensorFlow DeepLab模型动物园获得的 .

我们能够使用以下命令成功转换模型: -

CUDA_VISIBLE_DEVICES =“0”toco --output_file = toco256.tflite --graph_def_file = path / to / deeplab / deeplabv3_mnv2_pascal_trainval / frozen_inference_graph.pb --input_arrays = ImageTensor --output_arrays = SemanticPredictions --input_shapes = 1,256,256,3 --inference_input_type = QUANTIZED_UINT8 --inference_type = FLOAT --mean_values = 128 --std_dev_values = 127 --allow_custom_ops --post_training_quantize

tflite文件的大小约为2.25 Mb . 但是当我们尝试使用官方基准测试工具测试模型时,它失败并出现以下错误报告: -

bazel run -c opt tensorflow/contrib/lite/tools/benchmark:benchmark_model -- --graph=`realpath toco256.tflite`
INFO: Analysed target //tensorflow/contrib/lite/tools/benchmark:benchmark_model (0 packages loaded).
INFO: Found 1 target...
Target //tensorflow/contrib/lite/tools/benchmark:benchmark_model up-to-date:
  bazel-bin/tensorflow/contrib/lite/tools/benchmark/benchmark_model
INFO: Elapsed time: 0.154s, Critical Path: 0.00s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/tensorflow/contrib/lite/tools/benchmark/benchmark_model '--graph=path/to/deeplab/venINFO: Build completed successfully, 1 total action
STARTING!
Num runs: [50]
Inter-run delay (seconds): [-1]
Num threads: [1]
Benchmark name: []
Output prefix: []
Warmup runs: [1]
Graph: path/to/venv/tensorflow/toco256.tflite]
Input layers: []
Input shapes: []
Use nnapi : [0]
Loaded model path/to/venv/tensorflow/toco256.tflite
resolved reporter
Initialized session in 45.556ms
Running benchmark for 1 iterations 
tensorflow/contrib/lite/kernels/pad.cc:96 op_context.dims != 4 (3 != 4)
Node number 24 (PAD) failed to prepare.

Failed to invoke!
Aborted (core dumped)

我们也尝试了相同的命令,但没有包含'allow_custom_ops'和'post_training_quantize'选项,甚至使用了相同的输入大小1,513,513,3;但结果是一样的 .

此问题似乎与以下github问题类似:(https://github.com/tensorflow/tensorflow/issues/21266) . 然而,在TensorFlow的最新版本中,该问题应该是固定的 .

型号:http://download.tensorflow.org/models/deeplabv3_mnv2_pascal_trainval_2018_01_29.tar.gz Tensorflow版本:1.11 Bazel版本:0.17.2操作系统:Ubuntu 18.04

Android应用程序也无法正确加载模型(tflite interpretr)

那么,我们如何才能将分割模型正确转换为可用于Android设备推理的tflite格式?

更新: -

使用tensorflow 1.12,我们得到一个新错误:

$ bazel run -c opt tensorflow/lite/tools/benchmark:benchmark_model -- --graph=`realpath /path/to/research/deeplab/venv/tensorflow/toco256.tflite`

    tensorflow/lite/kernels/depthwise_conv.cc:99 params->depth_multiplier * SizeOfDimension(input, 3) != SizeOfDimension(filter, 3) (0 != 32)
    Node number 30 (DEPTHWISE_CONV_2D) failed to prepare.

此外,在tensorflow deeplab model zoo中使用相同模型的较新版本(3 Mb .pb文件)且depth_multiplier = 0.5时,我们得到了一个不同的错误: -

F tensorflow/lite/toco/graph_transformations/propagate_fixed_sizes.cc:116] Check failed: dim_x == dim_y (3 vs. 32)Dimensions must match

在这种情况下,我们使用相同的上述命令进行tflite转换;但我们甚至无法生成'tflite'文件作为输出 . 这似乎是深度乘数值的问题 . (甚至我们尝试将depth_multiplier参数作为参数在转换时) .

1 回答

  • 0

    我有同样的问题 . 来自https://github.com/tantara/JejuNet我看到他成功地将模型转换为tflite . 我请他帮忙,但遗憾的是现在没有回应 .

相关问题