【发布时间】:2020-11-03 04:36:29
【问题描述】:
!pip install tensorflow==2.2
import tensorflow as tf
converter = tf.compat.v1.lite.TFLiteConverter.from_keras_model( 'short-train.h5' ) # Your model's name
model = converter.convert()
file = open( 'model.tflite' , 'wb' )
file.write( model )
是我正在运行的代码。我收到以下错误:
AttributeError Traceback (most recent call last)
<ipython-input-8-38aae5855f2c> in <module>
1 get_ipython().system('pip install tensorflow==2.2')
2 import tensorflow as tf
----> 3 converter = tf.compat.v1.lite.TFLiteConverter.from_keras_model( 'short-train.h5' ) # Your model's name
4 model = converter.convert()
5 file = open( 'model.tflite' , 'wb' )
AttributeError: type object 'TFLiteConverter' has no attribute 'from_keras_model'
这是https://www.tensorflow.org/api_docs/python/tf/lite/TFLiteConverter给我的代码
这是 tensorflow 给出的确切语法。这里有什么问题?
编辑:我现在按照建议运行此代码:
import tensorflow as tf
# WHOLE MODEL
model = r'C:\Users\Owner\Anaconda3\face-mask-detector\mask_detector.model'
tflite_model = tf.keras.models.load_model(model)
converter = tf.lite.TFLiteConverter.from_keras_model(tflite_model)
tflite_save = converter.convert()
open("short-train.tflite", "wb").write(tflite_save)
但是我收到了这个错误:
ValueError: Unknown layer: Functional #after 尝试加载模型
我找不到有关此错误的任何有用信息。感谢您的宝贵时间
【问题讨论】:
标签: python tensorflow keras tensorflow-lite h5py