Bazel生成TFLite文件错误

之前在目标检测——TensorFlow Lite 安卓口罩人脸检测项目中使用到了Bazel来生成TFLite格式的模型再迁移到安卓端中使用,最近训练了一个语义分割的模型使用同样的方法生成TFLite模型却出现了问题。


编译命令:

bazel run tensorflow/lite/toco:toco -- \
--input_file=/home/well/mobile-segmentation/logs/frozen_graph.pb \
--output_file=/home/well/mobile-segmentation/logs/seg.tflite \ 
--input_shapes=1,769,769,3 \
--input_arrays=normalized_input_image_tensor \
--output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' \
--inference_type=FLOAT \
--allow_custom_ops 

报错:2020-04-26 09:43:52.704543: F tensorflow/lite/toco/tooling_util.cc:938] Check failed: GetOpWithOutput(model, output_array) Specified output array “TFLite_Detection_PostProcess” is not produced by any op in this graph. Is it a typo? This should not happen. If you trigger this error please send a bug report (with code to reporduce this error), to the TensorFlow Lite team.
已放弃 (核心已转储)

分析:GetOpWithOutput(model,output_array)此图中的任何操作均未生成指定的输出数组“ TFLite_Detection_PostProcess”,也就是说我们的模型输出跟我们命令中的不一致;然后分析了一下编译命令中的参数意义:

  • input_file:输入文件路径,也就是放.pb模型的位置。
  • output_file:输出文件,输出的路径和模型的名字,扩展名为.tflite。
  • input_shapes:输入维度。
  • input_arrays:模型输入名。
  • output_arrays:模型输出名。
  • inference_type:推断类型。
  • allow_custom_ops:是允许一些传统方法。

到这里问题的决绝方法就找到了,input_arrys和output_array必须对应模型中的输入输出的名字,参数值只要改成对应名字就可以了。


由于使用的是预训练模型,并不清楚网络的具体结构和名称,所以要使用其他方法来查看网络结构;
summarize_graph可以查看网络节点,在只有一个固化的权重文件而不知道具体的网络结构时非常有用。

bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=/home/well/mobile-segmentation/logs/frozen_graph.pb

在这里插入图片描述
从输出的结果可以看到,–input_layer=input_0、–input_layer_type=float、
–input_layer_shape=1,255,255,3、–output_layer=Cast,这样我们就得到了我们想要的参数名称。

如果出错的话可以尝试:

 ./configure
 bazel build tensorflow/tools/graph_transforms:summarize_graph
 bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=/home/well/mobile-segmentation/logs/frozen_graph.pb

修改后的编译命令:

 bazel run tensorflow/lite/toco:toco -- \
 --input_file=/home/well/mobile-segmentation/logs/frozen_graph.pb \
 --output_file=/home/well/mobile-segmentation/logs/seg255.tflite \ 
 --input_shapes=1,255,255,3 \--input_arrays=input_0 \
 --output_arrays=Cast \
 --inference_type=FLOAT \
 --allow_custom_ops 

最终成功编译生成TFLite文件!!!
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值