tf.keras HDF5模型和Keras HDF5模型 [英] tf.keras HDF5 Model and Keras HDF5 Model
问题描述
我想将Keras模型转换为Tensorflow Lite模型.当我检查了文档时,声明可以使用tf.keras HDF5模型作为输入.这是否意味着我可以将保存的HDF5 Keras模型用作输入或tf.keras HDF5模型和Keras HDF5模型是不同的东西?
文档: https://www.tensorflow.org/lite/convert >
我可以使用此API将Keras模型转换为Tensorflow Lite模型,但我尚未对其进行测试.我的代码:
converter = tf.lite.TFLiteConverter.from_keras_model_file(path + 'plant-
recognition-model.h5')
tflite_model = converter.convert()
with open('plant-recognition-model.tflite', 'wb') as f:
f.write(tflite_model)
tf.keras HDF5模型和Keras HDF5模型没有什么不同,除了不可避免的软件版本更新同步. 这是官方文档所说的:
tf.keras是TensorFlow对Keras API规范的实现.这是用于构建和训练模型的高级API,其中包括对TensorFlow特定功能的一流支持
如果转换器可以将keras模型转换为tf.lite,则将提供相同的结果.但是tf.lite的功能比tf.keras更受限制.如果此功能集还不够用,您仍然可以使用tensorflow并享受其其他优点.
也许不久之后,您的模型就可以在智能手机上运行了.
I want to convert a Keras model to Tensorflow Lite model. When I examined the documentation, it is stated that we can use tf.keras HDF5 models as input. Does it mean I can use my saved HDF5 Keras model as input to it or tf.keras HDF5 model and Keras HDF5 models are different things?
Documentation: https://www.tensorflow.org/lite/convert
Edit: I could convert my Keras model to Tensorflow Lite model with using this API, but I didn't test it yet. My code:
converter = tf.lite.TFLiteConverter.from_keras_model_file(path + 'plant-
recognition-model.h5')
tflite_model = converter.convert()
with open('plant-recognition-model.tflite', 'wb') as f:
f.write(tflite_model)
tf.keras HDF5 model and Keras HDF5 models are not different things, except for inevitable software version update synchronicity. This is what the official docs say:
tf.keras is TensorFlow's implementation of the Keras API specification. This is a high-level API to build and train models that includes first-class support for TensorFlow-specific functionality
If the convertor can convert a keras model to tf.lite, it will deliver same results. But tf.lite functionality is more limited than tf.keras. If this feature set is not enough for you, you can still work with tensorflow, and enjoy its other advantages.
May be, it won't take too long before your models can run on a smartphone.
这篇关于tf.keras HDF5模型和Keras HDF5模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!