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

前端 未结 7 836
不思量自难忘°
不思量自难忘° 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:45

    Converting a GraphDef from the session.

    converter = lite.TFLiteConverter.from_session(sess, in_tensors, out_tensors)
    tflite_model = converter.convert()
    open("converted_model.tflite", "wb").write(tflite_model)
    

    Converting a GraphDef from file.

    converter = lite.TFLiteConverter.from_frozen_graph(
    graph_def_file, input_arrays, output_arrays)
    tflite_model = converter.convert()
    open("converted_model.tflite", "wb").write(tflite_model)
    

    Converting a SavedModel.

    converter = lite.TFLiteConverter.from_saved_model(saved_model_dir)
    tflite_model = converter.convert()
    

提交回复
热议问题