Encountered unresolved custom op: TensorListFromTensor. Node number 4 (TensorListFromTensor) failed to prepare

Question:

I am new to Tensor flow and machine learning. Here I am trying to create a text classification of my own. I am facing below issue. I am getting below error while loading tflite model on Android.

 Process: org.tensorflow.lite.examples.textclassification, PID: 12031
java.lang.IllegalStateException: Internal error: Unexpected failure when preparing tensor allocations: Encountered unresolved custom op: TensorListFromTensor.
Node number 4 (TensorListFromTensor) failed to prepare.

    at org.tensorflow.lite.NativeInterpreterWrapper.allocateTensors(Native Method)
    at org.tensorflow.lite.NativeInterpreterWrapper.init(NativeInterpreterWrapper.java:96)
    at org.tensorflow.lite.NativeInterpreterWrapper.<init>(NativeInterpreterWrapper.java:61)
    at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:224)
    at org.tensorflow.lite.Interpreter.<init>(Interpreter.java:182)
    at org.tensorflow.lite.examples.textclassification.TextClassificationClient.loadModel(TextClassificationClient.java:139)
    at org.tensorflow.lite.examples.textclassification.TextClassificationClient.load(TextClassificationClient.java:129)
    at org.tensorflow.lite.examples.textclassification.MainActivity.lambda$onStart$1$MainActivity(MainActivity.java:65)
    at org.tensorflow.lite.examples.textclassification.-$$Lambda$MainActivity$3O7XdyFVukGQ46LZyOIpHdTRepg.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6898)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Py Notebook code

input = tf.keras.layers.Input(shape=(max_len,))
x = tf.keras.layers.Embedding(max_words, embed_size, weights=[embedding_matrix], trainable=False)(input)

x = tf.keras.layers.Bidirectional(tf.keras.layers.GRU(128, return_sequences=True, dropout=0.1,
                                                      recurrent_dropout=0.1))(x)

x = tf.keras.layers.Conv1D(64, kernel_size=3, padding="valid", kernel_initializer="glorot_uniform")(x)

avg_pool = tf.keras.layers.GlobalAveragePooling1D()(x)
max_pool = tf.keras.layers.GlobalMaxPooling1D()(x)

x = tf.keras.layers.concatenate([avg_pool, max_pool])

preds = tf.keras.layers.Dense(6, activation="sigmoid")(x)

model = tf.keras.Model(input, preds)

model.summary()

In python running below code also causing the same error

interpreter = tf.lite.Interpreter(model_path="xxx.tflite")
interpreter.allocate_tensors()

Error below
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-20-988ba8e1e2e5> in <module>
      1 interpreter = tf.lite.Interpreter(model_path="touch_tf.tflite")
----> 2 interpreter.allocate_tensors()

/usr/local/lib/python3.7/site-packages/tensorflow_core/lite/python/interpreter.py in allocate_tensors(self)
    240   def allocate_tensors(self):
    241     self._ensure_safe()
--> 242     return self._interpreter.AllocateTensors()
    243 
    244   def _safe_to_run(self):

/usr/local/lib/python3.7/site-packages/tensorflow_core/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py in AllocateTensors(self)
    108 
    109     def AllocateTensors(self):
--> 110         return _tensorflow_wrap_interpreter_wrapper.InterpreterWrapper_AllocateTensors(self)
    111 
    112     def Invoke(self):

RuntimeError: Encountered unresolved custom op: TensorListFromTensor.Node number 4 (TensorListFromTensor) failed to prepare.
Asked By: Gunjan Dave

||

Answers:

This link helped me resolve this issue.

Git Issue #29472

Setting converter.experimental_new_converter =True will help

Answered By: Gunjan Dave

I did so but later it caused an error while allocating tensors at the initialization of the interpreter.

please check this if you can be of any help with my issue.
Encountered unresolved custom op: SimpleMLCreateModelResource. Failed to allocate tensors

Answered By: Maiada Khaled