tensorflow: TfLite toco: fail kTensorflowMerge

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04 Beta
  • TensorFlow installed from (source or binary): Source
  • TensorFlow version (use command below): Master
  • Python version: 3.6
  • Bazel version (if compiling from source): 0.10.0
  • GCC/Compiler version (if compiling from source): gcc 4.8.5
  • CUDA/cuDNN version: 9.1 / 7.0.5
  • GPU model and memory: GTX 1070 Ti 6go & 16Go RAM
  • Exact command to reproduce: bazel-bin/tensorflow/contrib/lite/toco/toco –input_file=frozen_graph.pb –input_format=TENSORFLOW_GRAPHDEF –output_format=TFLITE –output_file=/tmp/test.tflite –inference_input_type=FLOAT –input_arrays=input_image –output_arrays=output_corner,output_mask –input_shapes=1,512,512,3

Describe the problem

I’m working on a FCN. I want to export my frozen graph to TfLite graph but it’s not working. I’m wondering why, but I guess it’s just due to the lack of maturity of TfLite (and probably some operator compatibility). In my case, it’s about the operator “Merge”. Someone can explain me if there is a way/trick to make it work ?

Source code / logs

2018-04-20 12:57:33.287154: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1268] Converting unsupported operation: LogicalOr
2018-04-20 12:57:33.302765: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 518 operators, 965 arrays (0 quantized)
2018-04-20 12:57:33.312501: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 477 operators, 902 arrays (0 quantized)
2018-04-20 12:57:33.325133: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 477 operators, 902 arrays (0 quantized)
2018-04-20 12:57:33.325335: F tensorflow/contrib/lite/toco/graph_transformations/resolve_tensorflow_switch.cc:95] Check failed: other_op->type == OperatorType::kTensorFlowMerge 
Aborted (core dumped)

I also make a summarize_graph for you, maybe it help

Found 1 possible inputs: (name=input_image, type=int32(3), shape=[1,?,?,3]) 
No variables spotted.
Found 2 possible outputs: (name=output_corner, op=Tile) (name=output_mask, op=Tile) 
Found 1471309 (1.47M) const parameters, 0 (0) variable parameters, and 51 control_edges
Op types used: 239 Const, 168 Switch, 36 FusedBatchNorm, 27 Add, 22 Identity, 21 Merge, 18 Conv2D, 15 Relu, 13 StridedSlice, 12 Shape, 7 Mul, 6 Cast, 5 MaxPool, 5 Pack, 5 RealDiv, 3 Slice, 3 Conv2DBackpropInput, 2 Tile, 2 Reshape, 2 RandomUniform, 2 PlaceholderWithDefault, 2 Greater, 2 Floor, 2 ConcatV2, 1 Placeholder, 1 Maximum, 1 LogicalOr, 1 ResizeBilinear, 1 Sigmoid, 1 Softmax, 1 Squeeze, 1 ExpandDims, 1 Sub, 1 ArgMax

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 31 (6 by maintainers)

Most upvoted comments

I have this issue when I convert networks with a placeholder as input:

is_training = tf.placeholder_with_default(False, shape=(), name="is_training")

Replacing this with

is_training = False

for inference lets me convert the model successfully. Making this manual change is not ideal though.

I think it is tensorflow/lite/toco/graph_transformations/resolve_tensorflow_switch.cc could be replaced with this one.

resolve_tensorflow_switch.zip

Actually we gave up using TOCO or even TensorFlow Lite, so I am not actively following this issue. I am not sure it works or not.

@arpitkh96 One quick suggestion is to make sure that you are not passing in a training model by setting keras.backend.set_learning_phase(False).

Additionally, TocoConverter has a from_keras_model_file function that makes it easier to do what you are doing, so I suggest using that. It is broken in 1.10, however, it has been fixed on the tf-nightly and in the 1.11 release.