1 回答

TA贡献1874条经验 获得超12个赞
TensorFlow Lite 模型包含权重和模型代码本身。您需要加载 Keras 模型(带权重),然后您将能够转换为 tflite 模型。
获取作者repo的副本,并执行get-networks.sh。您只需要data/lp-detector/wpod-net_update1.h5
车牌检测器,这样您就可以提前停止下载。
深入研究代码,您可以在keras utils找到准备好的负载模型函数。
获得模型对象后,可以将其转换为 tflite。
Python3、TF2.4测试:
import sys, os
import tensorflow as tf
import traceback
from os.path import splitext, basename
print(tf.__version__)
mod_path = "data/lp-detector/wpod-net_update1.h5"
def load_model(path,custom_objects={},verbose=0):
#from tf.keras.models import model_from_json
path = splitext(path)[0]
with open('%s.json' % path,'r') as json_file:
model_json = json_file.read()
model = tf.keras.models.model_from_json(model_json, custom_objects=custom_objects)
model.load_weights('%s.h5' % path)
if verbose: print('Loaded from %s' % path)
return model
keras_mod = load_model(mod_path)
converter = tf.lite.TFLiteConverter.from_keras_model(keras_mod)
tflite_model = converter.convert()
# Save the TF Lite model.
with tf.io.gfile.GFile('model.tflite', 'wb') as f:
f.write(tflite_model)
祝你好运!
添加回答
举报