首页 > 解决方案 > 在珊瑚板上使用非量化的 deeplab 模型

问题描述

我在珊瑚开发板上使用了 deeplab v3 的量化模型。结果不是很精确,所以我想使用非量化模型。

我可以找到 deeplab 的 tflite 非量化模型,所以我想生成它。我在 Tensorflow github 上下载了一个 xception65_coco_voc_trainval 模型: xception65_coco_voc_trainval

然后我使用该命令来转换输入:

bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph="/path/to/xception65_coco_voc_trainval.pb" \
--out_graph="/path/to/xception65_coco_voc_trainval_flatten.pb" \
--inputs='ImageTensor' \
--outputs='SemanticPredictions' \
--transforms='
    strip_unused_nodes(type=quint8, shape="1,513,513,3")
    flatten_atrous_conv
    fold_constants(ignore_errors=true, clear_output_shapes=false)
    fold_batch_norms
    fold_old_batch_norms
    remove_device
    sort_by_execution_order

然后我用这个命令生成 tflite 文件:

tflite_convert \
  --graph_def_file="/tmp/deeplab_mobilenet_v2_opt_flatten_static.pb" \
  --output_file="/tmp/deeplab_mobilenet_v2_opt_flatten_static.tflite" \
  --output_format=TFLITE \
  --input_shape=1,513,513,3 \
  --input_arrays="ImageTensor" \
  --inference_type=FLOAT \
  --inference_input_type=QUANTIZED_UINT8 \
  --std_dev_values=128 \
  --mean_values=128 \
  --change_concat_input_ranges=true \
  --output_arrays="SemanticPredictions" \
  --allow_custom_ops

这个命令为我生成了一个 tflite 文件。我将文件下载到我的珊瑚开发板上并尝试运行它。

我在 github 上使用该示例来尝试我在珊瑚上的 deeplab 模型: deeplab oncoral

当我启动程序时出现错误:

 terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted

错误来自该行:

engine = BasicEngine(args.model)

标签: tensorflowgoogle-coral

解决方案


推荐阅读