tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone
https://tensorflow.org
Apache License 2.0
186.4k stars 74.3k forks source link

Tflite does not seem to support LSTM. #21377

Closed Arsenal591 closed 6 years ago

Arsenal591 commented 6 years ago

System information

Source code / logs

See below.

Describe the problem

I'm trying to convert a .pb graph into tflite format, which containes a bi-directional LSTM. However, whenever I run the command:

toco --graph_def_file=opt_frozen.pb \
--output_file= output.tflite \
--output_format=TFLITE \
--inference_type=FLOAT \
--inference_input_type=FLOAT \
--input_arrays=[input_tensor_names] \
--output_arrays=[output_tensor_names]

It failed with following error messages:

2018-08-03 14:35:41.259412: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.259490: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.271357: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.271401: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.271439: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.271454: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.279573: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.279626: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.279989: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280020: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280043: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280087: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayV3
2018-08-03 14:35:41.280107: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayV3
2018-08-03 14:35:41.280123: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280141: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280163: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: LogicalAnd
2018-08-03 14:35:41.280175: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: LoopCond
2018-08-03 14:35:41.280224: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280266: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280303: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Exit
2018-08-03 14:35:41.280317: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArraySizeV3
2018-08-03 14:35:41.280340: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayGatherV3
2018-08-03 14:35:41.280362: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: ReverseV2
2018-08-03 14:35:41.280385: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280412: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280433: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280469: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayV3
2018-08-03 14:35:41.280487: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayV3
2018-08-03 14:35:41.280502: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280519: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280535: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: LogicalAnd
2018-08-03 14:35:41.280546: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: LoopCond
2018-08-03 14:35:41.280588: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280626: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280656: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Exit
2018-08-03 14:35:41.280671: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArraySizeV3
2018-08-03 14:35:41.280693: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayGatherV3
2018-08-03 14:35:41.280965: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayScatterV3
2018-08-03 14:35:41.280982: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.280997: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayReadV3
2018-08-03 14:35:41.281074: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayWriteV3
2018-08-03 14:35:41.281102: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: ReverseV2
2018-08-03 14:35:41.281123: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayScatterV3
2018-08-03 14:35:41.281138: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: Enter
2018-08-03 14:35:41.281157: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayReadV3
2018-08-03 14:35:41.281228: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1366] Converting unsupported operation: TensorArrayWriteV3

And I assume that LSTM is not currently supported in tflite. So is that the case? And if it's true, is there any way that I can work around this problem?

aselle commented 6 years ago

You can generate a LSTM cell indidivually and manually loop back state (i.e. don't use static_rnn or dynamic_rnn). It will convert the lstm as individual operators. For more help, please provide a simple example that you are trying to run.

tensorflowbutler commented 6 years ago

It has been 14 days with no activity and the awaiting response label was assigned. Is this still an issue?

tofulawrence commented 6 years ago

Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks!

robbiemu commented 5 years ago

@aselle I have a simple example to volunteer :) I wish you would take mine as an example! Full source is https://colab.research.google.com/drive/1sB8vv3TM5Sp45TicJ8PxEvpUAX42XqPY and I can gladly provide sample data as well.

Here's the part specific to consrtructing the model:

from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout

regressor = Sequential()
regressor.add(LSTM(units=nh, return_sequences=True, 
                   input_shape=(timesteps, dim)))

layers = (len(endog) + 1) if len(endog) > 1 else 2 # 4
for i in range(1, layers):
  if i < layers - 1:
    cell = LSTM(units=nh, return_sequences=True)
  else:
    cell = LSTM(units=nh)

  regressor.add(cell)

regressor.add(Dropout(dropout)) # 0.2
regressor.add(Dense(units=dim))

regressor.compile(optimizer='adam', loss='mean_squared_error')

this is a pretty small/simple LSTM for use with categorical and continuous time series data, with, for my data and prediction range, about 4 layers of about 12 nodes + dropout and output.