使用 toco 的 TensorFlow Lite : Error converting to . tflite

标签 tensorflow tensorflow-serving tensorflow-lite

我正在尝试将 TensorFlow 卡住模型转换为 tflite 模型。当我运行 toco 时,我收到一条错误消息,如下所示

F tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:982] Check failed: input_dims.size() == 4 (2 vs. 4)

这是我如何称呼 toco:

bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_format=TENSORFLOW_GRAPHDEF \
--input_file=/tmp/output_graph.pb \
--output_format=TFLITE \
--output_file=/tmp/my_model.lite \
--inference_type=FLOAT \
--inference_input_type=FLOAT \
--input_arrays=input_layer \
--output_arrays=classes_tensor\
--input_shapes=1,227,227,3

这是我在操作过程中终端打印出来的:

INFO: Analysed 0 targets (4 packages loaded).
INFO: Found 0 targets...
INFO: Elapsed time: 5.267s, Critical Path: 0.03s
INFO: Build completed successfully, 1 total action
2018-01-05 10:24:23.011483: W tensorflow/contrib/lite/toco/toco_cmdline_flags.cc:178] --input_type is deprecated. It was an ambiguous flag that set both --input_data_types and --inference_input_type. If you are trying to complement the input file with information about the type of input arrays, use --input_data_type. If you are trying to control the quantization/dequantization of real-numbers input arrays in the output file, use --inference_input_type.
2018-01-05 10:24:25.853112: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1122] Converting unsupported operation: IsVariableInitialized
2018-01-05 10:24:25.853197: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1122] Converting unsupported operation: RefSwitch
2018-01-05 10:24:25.853241: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1122] Converting unsupported operation: RandomShuffleQueueV2
2018-01-05 10:24:25.853268: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1122] Converting unsupported operation: QueueDequeueUpToV2
2018-01-05 10:24:26.207160: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 64 operators, 90 arrays (0 quantized)
2018-01-05 10:24:27.327055: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 15 operators, 33 arrays (0 quantized)
2018-01-05 10:24:27.327262: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 2: 15 operators, 34 arrays (0 quantized)
2018-01-05 10:24:27.327356: F tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:982] Check failed: input_dims.size() == 4 (2 vs. 4)
/home/olu/Dev/scratch_train_sign/freeze_graph_tf.sh: line 28:  8881 Aborted 

我进入了propagate_fixed_sizes.cc文件,在第982行附近我发现了下面的评论

// The current ArgMax implementation only supports 4-dimensional inputs with
// the last dimension as the axis to perform ArgMax for.

我的训练代码中唯一使用 ArgMax 的地方如下:

 predictions = { "classes": tf.argmax(input=logits, axis=1, name="classes_tensor"), "probabilities": tf.nn.softmax(logits, name="softmax_tensor") }

你知道解决这个问题的方法是什么吗?对此问题的解决方案将不胜感激。

最佳答案

在 GitHub 上的 TensorFlow 错误跟踪器上将此问题提出后,答案归结为 TLite 目前并不完全支持 ArgMax。 Link

关于使用 toco 的 TensorFlow Lite : Error converting to . tflite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48112174/

相关文章:

swift - 如何不基于图像分类快速运行tflite模型

tensorflow - 由于内部错误,无法在解释器上运行 tflite 模型

python-3.x - 无法在 Windows 10 中运行 Tensorflow

python - Keras load_model 返回传递给优化器的意外关键字参数 : amsgrad

tensorflow - 如何使用Tflearn构建词嵌入模型?

python - 如何将 tf.example 发送到 TensorFlow Serving gRPC 预测请求中

tensorflow - 尝试通过 Tensorflow Serving 使用 Universal Sentence Encoder Lite/2

python - 如何在 TensorFlow 图中正确引发异常

python-3.x - Keras: TypeError: run() 得到了一个意外的关键字参数 'kernel_regularizer'

python - Nvidia Jetson 上的 Tensorflow Lite