keras .h5转移动端的.tflite文件

以前tensorflow有bug 在winodws下无法转,但现在好像没有问题了,代码如下

将keras 下的mobilenet_v2转成了tflite

from keras.backend import clear_session
import numpy as np
import tensorflow as tf
clear_session()
np.set_printoptions(suppress=True)
input_graph_name = "../models/weights.best_mobilenet224.h5"
output_graph_name = input_graph_name[:-3] + '.tflite'
converter = tf.lite.TFLiteConverter.from_keras_model_file(model_file=input_graph_name)
converter.post_training_quantize = True
#在windows平台这个函数有问题,无法正常使用
tflite_model = converter.convert()
open(output_graph_name, "wb").write(tflite_model)
print ("generate:",output_graph_name)

你可能感兴趣的:(android,开发学习,python)