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)
祝你好運!
添加回答
舉報