title: How do you convert a .onnx to tflite?
body: <p>I've exported my model to ONNX via:</p>
  
  <pre><code># Export the model
  torch_out = torch.onnx._export(learn.model,             # model being run
                             x,                       # model input (or a tuple for multiple inputs)
                            EXPORT_PATH + "mnist.onnx", # where to save the model (can be a file or file-like object)
                             export_params=True)      # store the trained parameter weights inside the model file
  </code></pre>
  
  <p>And now I am trying to convert the model to a Tensorflow Lite file so that I can do inference on Android. Unfortunately, PyTorch/Caffe2 support is fairly lacking or too complex for Android but Tensorflow appears much simpler.</p>
  
  <p>The documentation for ONNX to Tflite is pretty light on this.</p>
  
  <p>I've tried exporting to a Tensorflow GraphDef proto via:</p>
  
  <p><code>tf_rep.export_graph(EXPORT_PATH + 'mnist-test/mnist-tf-export.pb')</code></p>
  
  <p>And then running <code>toco</code>:</p>
  
  <pre><code>toco \
  --graph_def_file=mnist-tf-export.pb \
  --input_format=TENSORFLOW_GRAPHDEF \
  --output_format=TFLITE \
  --inference_type=FLOAT \
  --input_type=FLOAT \
  --input_arrays=0 \
  --output_arrays=add_10 \
  --input_shapes=1,3,28,28 \
  --output_file=mnist.tflite`
  </code></pre>
  
  <p>When I do though I get the following error:</p>
  
  <pre><code>File "anaconda3/lib/python3.6/site-packages/tensorflow/lite/python/convert.py", line 172, in toco_convert_protos
      "TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
  tensorflow.lite.python.convert.ConverterError: TOCO failed. See console for info.
  2018-11-06 16:28:33.864889: I tensorflow/lite/toco/import_tensorflow.cc:1268] Converting unsupported operation: PyFunc
  2018-11-06 16:28:33.874130: F tensorflow/lite/toco/import_tensorflow.cc:114] Check failed: attr.value_case() == AttrValue::kType (1 vs. 6)
  </code></pre>
  
  <p>Further, even when I run the command I don't know what to specify for the input_arrays or output_arrays since the model was originally built in PyTorch.</p>
  
  <p>Has anyone successfully converted their ONNX model to TFlite?</p>
  
  <p>Here's the ONNX file I'm trying to convert: <a href="https://drive.google.com/file/d/1sM4RpeBVqPNw1WeCROpKLdzbSJPWSK79/view?usp=sharing" rel="noreferrer">https://drive.google.com/file/d/1sM4RpeBVqPNw1WeCROpKLdzbSJPWSK79/view?usp=sharing</a></p>
  
  <p>Extra info</p>
  
  <ul>
  <li>Python 3.6.6 :: Anaconda custom (64-bit)</li>
  <li>onnx.<strong>version</strong> = '1.3.0'</li>
  <li>tf.<strong>version</strong> = '1.13.0-dev20181106'</li>
  <li>torch.<strong>version</strong> = '1.0.0.dev20181029'</li>
  </ul>