如何解决从 Keras LSTM 模型转换后无法在 Android 中导入 Tensor flow lite 模型
我是机器学习和深度学习的新手。我试图通过将 Keras LSTM 模型转换为 .tflite 文件在 Android 应用程序中使用它,但是当我尝试在 android studio 中导入文件时,导入失败并显示“This Tensor flow lite 模型无效”的消息
我使用了张量流网站上提到的转换代码。
问题的解决方案是什么?
创建模型:
model = keras.Sequential()
model.add(
keras.layers.Bidirectional(
keras.layers.LSTM(
units=128,input_shape=[X_train.shape[1],X_train.shape[2]]
)
)
)
model.add(keras.layers.Dropout(rate=0.5))
model.add(keras.layers.Dense(units=128,activation='tanh'))
model.add(keras.layers.Dense(y_train.shape[1],activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['acc'])
模型摘要:
Model: "sequential_4"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
bidirectional (Bidirectional (None,256) 135168
_________________________________________________________________
dropout_3 (Dropout) (None,256) 0
_________________________________________________________________
dense_7 (Dense) (None,128) 32896
_________________________________________________________________
dense_8 (Dense) (None,11) 1419
=================================================================
Total params: 169,483
Trainable params: 169,483
Non-trainable params: 0
从 tflite 的转换:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
# Save the model.
with open('model_tensor.tflite','wb') as f:
f.write(tflite_model)
在 Android 中导入
解决方法
该问题与 Android Studio 无法导入 LSTM 模型有关。
此修复将在 Android Studio 4.2 中推出。现在,下载测试版,它将导入 LSTM 模型 (tflite)
这是已结束的问题和我的对话:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。