Skip to content

Error converting custom model to .tflite using Toco #21714

@gmalsagov

Description

@gmalsagov

System information

  • Have I written custom code: Yes, see neural net structure here
  • OS Platform and Distribution: Mac OS X 10.13.4
  • TensorFlow installed from (source or binary): pip (binary)
  • TensorFlow version (use command below): 1.10.0
  • Python version: 2.7.10
  • Bazel version (if compiling from source): 0.15.2-homebrew
  • GCC/Compiler version (if compiling from source): v1.10.0-rc1-19-g656e7a2b34
  • CUDA/cuDNN version: N/A
  • GPU model and memory: N/A
  • Exact command to reproduce:
    toco
    --graph_def_file='path to frozen_model.pb'
    --input_format=TENSORFLOW_GRAPHDEF
    --output_format=TFLITE
    --inference_type=FLOAT
    --input_type=INT
    --input_arrays=input_x
    --output_arrays=output/predictions
    --input_shapes=1,78
    --output_file='path to model.tflite'

Describe the problem

I have a Tensorflow Convolutional Neural Network model for Multi-class Sentiment Analysis. I removed Dropout layer from the frozen model and it produces inference fine. When I am trying to convert it into a TfLite version using Toco I am getting an error that has something to do with dimensions of an input tensor (see error below). This tensor leads to a convolution tensor whose function takes a 4d input tensor.

2018-08-19 15:27:50.977853: F tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:130] Check failed: input_shape.dimensions_count() == 4 Conv ops require 4D inputs. Input array "embedding/ExpandDims" is 3D.

Output from terminal:

`
2018-08-19 15:27:45.418932: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
File "/tensorflow/venv/bin/toco", line 11, in
sys.exit(main())
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 370, in main
app.run(main=run_main, argv=sys.argv[:1])
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 366, in run_main
_convert_model(tflite_flags)
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 143, in _convert_model
output_data = converter.convert()
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/contrib/lite/python/lite.py", line 374, in convert
dump_graphviz_video=self.dump_graphviz_video)
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 246, in toco_convert
input_data.SerializeToString())
File "/tensorflow/venv/lib/python2.7/site-packages/tensorflow/contrib/lite/python/convert.py", line 106, in toco_convert_protos
(stdout, stderr))
RuntimeError: TOCO failed see console for info.
2018-08-19 15:27:50.968669: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 40 operators, 57 arrays (0 quantized)
2018-08-19 15:27:50.975773: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 40 operators, 57 arrays (0 quantized)
2018-08-19 15:27:50.977853: F tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:130] Check failed: input_shape.dimensions_count() == 4 Conv ops require 4D inputs. Input array "embedding/ExpandDims" is 3D.

None
`

Source code / logs

I am using tf.expand_dims command only when declaring embedding layer to expand tensor to 4d prior to feeding it into a tf.nn.conv2d function:

self.embedded_chars_expanded = tf.expand_dims(self.embedded_chars, -1) conv = tf.nn.conv2d(self.embedded_chars, W, strides=[1, 1, 1, 1], padding='VALID', name='conv')

Does this mean that tensorflow lite doesn't support expand dims yet? Would appreciate an explanation or any possible walkarounds for my issue.

Thanks

Metadata

Metadata

Assignees

Labels

comp:liteTF Lite related issues

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions