作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 tensorflow 和机器学习的新手。在这里,我尝试创建自己的文本分类。我面临以下问题。我在 Android 上加载 tflite 模型时遇到以下错误。
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 笔记本代码
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()
在 python 中运行下面的代码也会导致相同的错误
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.
最佳答案
关于python - 遇到 Unresolved 自定义操作 : TensorListFromTensor. 节点号 4 (TensorListFromTensor) 准备失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59785516/
我是 tensorflow 和机器学习的新手。在这里,我尝试创建自己的文本分类。我面临以下问题。我在 Android 上加载 tflite 模型时遇到以下错误。 Process: org.tenso
我是一名优秀的程序员,十分优秀!