TOCO无法使用--allow_custom_ops转换不受支持的操作

时间:2019-07-15 19:33:39

标签: android tensorflow tensorflow-lite toco

我正在尝试转换在pascal voc数据集(https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md)上训练的mobilenet_v2模型。

我想推断出1024x1024的分辨率,因此我使用以下命令导出了模型。

 python export_model.py \
--checkpoint_path model/model.ckpt-30000 \
--export_path ./frozen_inference_graph.pb \
--model_variant="mobilenet_v2" \
--num_classes=21 \
--crop_size=1024 \
--crop_size=1024 \
--inference_scales=1.0

然后我使用toco命令将模型转换为tflite。

toco --graph_def_file=/home/abdullah/models-master/research   /frozen_casted.pb --input_format=TENSORFLOW_GRAPHDEF                                                         

--output_format=TFLITE  

--output_file=deeplabv3_mnv2_pascal_trainval.tflite   
--inference_type=FLOAT --inference_input_type=QUANTIZED_UINT8
--input_arrays=ImageTensor 
--output_arrays=SemanticPredictions
--input_shapes=1,1024,1024,3 --default_ranges_min=0 
--default_ranges_max=255 --allow_custom_ops  
--std_dev_values=128 --mean_values=1

然后将模型正确地转换为tflite:

    2019-07-16 00:28:18.188009: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1171] Converting unsupported operation: Equal
2019-07-16 00:28:18.188052: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1171] Converting unsupported operation: Equal
2019-07-16 00:28:18.188067: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1171] Converting unsupported operation: LogicalOr
2019-07-16 00:28:18.188093: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1171] Converting unsupported operation: Unpack
2019-07-16 00:28:18.188134: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1171] Converting unsupported operation: LogicalAnd
2019-07-16 00:28:18.192256: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1171] Converting unsupported operation: ResizeNearestNeighbor
2019-07-16 00:28:18.203603: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 813 operators, 1237 arrays (0 quantized)
2019-07-16 00:28:18.232795: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 801 operators, 1215 arrays (0 quantized)
2019-07-16 00:28:18.269909: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 801 operators, 1215 arrays (0 quantized)
2019-07-16 00:28:18.293777: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 132 operators, 325 arrays (0 quantized)
2019-07-16 00:28:18.296414: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before dequantization graph transformations: 132 operators, 325 arrays (0 quantized)
2019-07-16 00:28:18.298905: I tensorflow/contrib/lite/toco/allocate_transient_arrays.cc:311] Total transient array allocated size: 28311552 bytes, theoretical optimal value: 25165824 bytes.
2019-07-16 00:28:18.299732: W tensorflow/contrib/lite/toco/tflite/operator.cc:661] Ignoring unsupported attribute type with key '_output_shapes'
2019-07-16 00:28:18.299743: W tensorflow/contrib/lite/toco/tflite/operator.cc:661] Ignoring unsupported attribute type with key 'T'
2019-07-16 00:28:18.299946: W tensorflow/contrib/lite/toco/tflite/operator.cc:661] Ignoring unsupported attribute type with key 'T'
2019-07-16 00:28:18.299956: W tensorflow/contrib/lite/toco/tflite/operator.cc:661] Ignoring unsupported attribute type with key '_output_shapes'

但是当我在tflite上运行模型时,会出现以下错误。

  

java.lang.IllegalArgumentException:内部错误:无法创建解释器:找不到版本1的名称“ ExpandDims”的自定义操作       注册失败。

为了进行转换,我使用了tensorflow tensorflow =='1.6.0-rc1'

build.gradle中的tflite实现是实现'org.tensorflow:tensorflow-lite:+'

我不知道我在哪里失败,请帮助我。

0 个答案:

没有答案