How to convert keras(h5) file to a tflite file?

前端 未结 7 840
不思量自难忘°
不思量自难忘° 2021-01-31 19:25

I got an keras(h5) file. I need to convert it to tflite?? I researched, First i need to go via h5 -> pb -> tflite (because h5 - tflite sometimes results in some issue)

7条回答
  •  一个人的身影
    2021-01-31 19:54

    This worked for me on Windows 10 using Tensorflow 2.1.0 and Keras 2.3.1

    import tensorflow as tf
    
    model = tf.keras.models.load_model('model.h5')
    converter = tf.lite.TFLiteConverter.from_keras_model(model)
    tflite_model = converter.convert()
    open("converted_model.tflite", "wb").write(tflite_model)
    

提交回复
热议问题