

RuntimeError: TOCO failed see console for info.ī' 10:40:25.228797: I tensorflow/contrib/lite/toco/graph_transformations/graph_:39] Before Removing unused ops: 2 operators, 5 arrays (0 quantized)\n write( tflite_model) keras_model.summary() for each of the valid six combinations:įile "/usr/stud/staab/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/lite/python/lite.py", line 374, in convertĭump_graphviz_video=self.dump_graphviz_video)įile "/usr/stud/staab/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/lite/python/convert.py", line 246, in toco_convertįile "/usr/stud/staab/anaconda3/envs/tensorflow/lib/python3.5/site-packages/tensorflow/contrib/lite/python/convert.py", line 106, in toco_convert_protos With open( "tflite_model.tflite", "wb") as f: f. from_keras_model_file( "keras_model.hdf5") Overwrite = True, include_optimizer = True)Ĭonverter = lite. Save_model( model = keras_model, filepath = "keras_model.hdf5", compile( loss = 'categorical_crossentropy', optimizer = 'sgd', metrics =) # transform = Reshape((-1, 10, 42))(input) # (A) transform = Lambda( lambda x: reshape( x, ( - 1, 10, 42)))( input) # (B) # transform = Lambda(lambda x: squeeze(x, axis=-1))(input) # (C) # transform = Lambda(lambda x: b_squeeze(x, axis=-1))(input) # (D) permute = Permute(( 2, 1))( transform) # (E) # permute = Lambda(lambda x: permute_dimensions(x, (0,2,1)))(transform) # (F) keras_model = Model( inputs =, outputs =) contrib import lite input = Input( shape =( 10, 42, 1)) backend import squeeze as b_squeeze from tensorflow import reshape, squeeze from tensorflow. backend import permute_dimensions from tensorflow. layers import Input, Lambda, Permute, Reshape from tensorflow. models import save_model from tensorflow.


It uses split, concatenate and reshape operations and you find it at the end of this page after the tracebacks.įrom tensorflow.
Tensorflow permute dimensions code#
The expected result is the minimum example code running without errors and producing a tflite model file from the converted keras model file.Įdit: For the time being and for everyone with the same problem, I wrote an updated minimum example code with an "emulated" permute layer as a workaround. If all permute layers (E, F) are commented out and only one transform layer (B) or (C) or (D) is commented in and the outputs of Model is set to, the model also compiles and the TocoConverter produces a tflite-file.īut for each combination of (B-C) and (E, F) being commented in so that one transform layer and one permute layer is there, the TocoConverter doesn't produce a tflite-file although the model compiles and the model summary looks as it should. If all transform layers (A-D) are commented out and only one permute layer (E) or (F) is commented in, directly gets passed input and an input shape of (2,3,1) for (E) or (0,2,3,1) for (F), the model compiles and the TocoConverter produces a tflite-file. In the same way it doesn't matter whether the Keras permute layer (E) or the backend version (F) is commented in. However, lines (B), (C) and (D) all work fine and it doesn't matter which one is commented in. Its output shape would be (None, None, 10, 42). The native Keras reshape layer (A) is the only one that doesn't work because it doesn't support dimensionality reduction.

The input layer expects the last dimension to be 1, the transform layer being either a reshape or a squeeze layer gets rid of the 1, and the permutation layer just pushes the first dimension after the batch size to the end.
Tensorflow permute dimensions Pc#
The code example below containing a model with an input, "transformation" and permute layer compiles fine on pc and it is also possible to call predict()on it and getting the expected results. Exact command to reproduce: see minimum example code below.GPU model and memory: NVIDIA TITAN Xp, 12196MiB.GCC/Compiler version (if compiling from source):.Bazel version (if compiling from source):.TensorFlow version (use command below): v1.10.1-0-g4dcfddc5d1 1.10.1.TensorFlow installed from (source or binary): binary.iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:. OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04.Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No.
