title: Convert Tensorflow1.12 model to Tensorflow Lite (TFLite)
body: <p>I am trying to convert a model that I created in Tensorflow 1.12 to Tensorflow Lite.</p>
  <p>I use this Code:</p>
  <pre><code>import numpy as np
  import tensorflow as tf
  
  # Generate tf.keras model.
  model = tf.keras.models.Sequential()
  model.add(tf.keras.layers.Dense(2, input_shape=(3,)))
  model.add(tf.keras.layers.RepeatVector(3))
  model.add(tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(3)))
  model.compile(loss=tf.keras.losses.MSE,
                optimizer=tf.keras.optimizers.RMSprop(lr=0.0001),
                metrics=[tf.keras.metrics.categorical_accuracy],
                sample_weight_mode='temporal')
  
  x = np.random.random((1, 3))
  y = np.random.random((1, 3, 3))
  model.train_on_batch(x, y)
  model.predict(x)
  
  # Save tf.keras model in HDF5 format.
  keras_file = &quot;keras_model.h5&quot;
  tf.keras.models.save_model(model, keras_file)
  
  # Convert to TensorFlow Lite model.
  converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_file)
  tflite_model = converter.convert()
  open(&quot;converted_model.tflite&quot;, &quot;wb&quot;).write(tflite_model)
  </code></pre>
  <p>I took this Code example from the website <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/r1/convert/python_api.md#pre_tensorflow_1.12" rel="nofollow noreferrer">https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/g3doc/r1/convert/python_api.md#pre_tensorflow_1.12</a>.
  Because I am using Tensorflow 1.12 I modified the line</p>
  <pre><code>converter = tf.lite.TFLiteConverter.from_keras_model_file(keras_file)
  </code></pre>
  <p>to</p>
  <pre><code>converter = tf.contrib.lite.TFLiteConverter.from_keras_model_file(keras_file)
  </code></pre>
  <p>as suggested in the link above.
  When I ran this Code I got this info:</p>
  <pre><code>INFO:tensorflow:Froze 4 variables.
  INFO:tensorflow:Converted 4 variables to const ops.
  </code></pre>
  <p>Afterwards I got this error:</p>
  <hr />
  <pre><code>------------------------------
  RuntimeError                              Traceback (most recent call last)
  &lt;ipython-input-21-81a9e7060f2c&gt; in &lt;module&gt;
       23 # Convert to TensorFlow Lite model.
       24 converter = tf.contrib.lite.TFLiteConverter.from_keras_model_file(keras_file)
  ---&gt; 25 tflite_model = converter.convert()
       26 open(&quot;converted_model.tflite&quot;, &quot;wb&quot;).write(tflite_model)
  
  ~\Anaconda3\envs\tensorflow1.12\lib\site-packages\tensorflow\contrib\lite\python\lite.py in convert(self)
      451           input_tensors=self._input_tensors,
      452           output_tensors=self._output_tensors,
  --&gt; 453           **converter_kwargs)
      454     else:
      455       # Graphs without valid tensors cannot be loaded into tf.Session since they
  
  ~\Anaconda3\envs\tensorflow1.12\lib\site-packages\tensorflow\contrib\lite\python\convert.py in toco_convert_impl(input_data, input_tensors, output_tensors, *args, **kwargs)
      340   data = toco_convert_protos(model_flags.SerializeToString(),
      341                              toco_flags.SerializeToString(),
  --&gt; 342                              input_data.SerializeToString())
      343   return data
      344 
  
  ~\Anaconda3\envs\tensorflow1.12\lib\site-packages\tensorflow\contrib\lite\python\convert.py in toco_convert_protos(model_flags_str, toco_flags_str, input_data_str)
      133     else:
      134       raise RuntimeError(&quot;TOCO failed see console for info.\n%s\n%s\n&quot; %
  --&gt; 135                          (stdout, stderr))
      136 
      137 
  
  RuntimeError: TOCO failed see console for info.
  b'C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:523: FutureWarning: Passing (type, 1) or \'1type\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \'(1,)type\'.\r\n  _np_qint8 = np.dtype([(&quot;qint8&quot;, np.int8, 1)])\r\nC:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:524: FutureWarning: Passing (type, 1) or \'1type\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \'(1,)type\'.\r\n  _np_quint8 = np.dtype([(&quot;quint8&quot;, np.uint8, 1)])\r\nC:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:525: FutureWarning: Passing (type, 1) or \'1type\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \'(1,)type\'.\r\n  _np_qint16 = np.dtype([(&quot;qint16&quot;, np.int16, 1)])\r\nC:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:526: FutureWarning: Passing (type, 1) or \'1type\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \'(1,)type\'.\r\n  _np_quint16 = np.dtype([(&quot;quint16&quot;, np.uint16, 1)])\r\nC:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:527: FutureWarning: Passing (type, 1) or \'1type\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \'(1,)type\'.\r\n  _np_qint32 = np.dtype([(&quot;qint32&quot;, np.int32, 1)])\r\nC:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\python\\framework\\dtypes.py:532: FutureWarning: Passing (type, 1) or \'1type\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \'(1,)type\'.\r\n  np_resource = np.dtype([(&quot;resource&quot;, np.ubyte, 1)])\r\nTraceback (most recent call last):\r\n  File &quot;C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\contrib\\lite\\toco\\python\\tensorflow_wrap_toco.py&quot;, line 18, in swig_import_helper\r\n    fp, pathname, description = imp.find_module(\'_tensorflow_wrap_toco\', [dirname(__file__)])\r\n  File &quot;C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\imp.py&quot;, line 297, in find_module\r\n    raise ImportError(_ERR_MSG.format(name), name=name)\r\nImportError: No module named \'_tensorflow_wrap_toco\'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File &quot;C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\Scripts\\toco_from_protos-script.py&quot;, line 6, in &lt;module&gt;\r\n    from tensorflow.contrib.lite.toco.python.toco_from_protos import main\r\n  File &quot;C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\contrib\\lite\\toco\\python\\toco_from_protos.py&quot;, line 22, in &lt;module&gt;\r\n    from tensorflow.contrib.lite.toco.python import tensorflow_wrap_toco\r\n  File &quot;C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\contrib\\lite\\toco\\python\\tensorflow_wrap_toco.py&quot;, line 28, in &lt;module&gt;\r\n    _tensorflow_wrap_toco = swig_import_helper()\r\n  File &quot;C:\\Users\\.\\Anaconda3\\envs\\tensorflow1.12\\lib\\site-packages\\tensorflow\\contrib\\lite\\toco\\python\\tensorflow_wrap_toco.py&quot;, line 20, in swig_import_helper\r\n    import _tensorflow_wrap_toco\r\nModuleNotFoundError: No module named \'_tensorflow_wrap_toco\'\r\n'
  None
  
  Could someone help to solve this?
  </code></pre>