How To Convert Just A H5 File To A Tflite File?
I'm trying to run license plate detection on Android. So first of all I find this tutorial: https://medium.com/@quangnhatnguyenle/detect-and-recognize-vehicles-license-plate-with-m
Solution 1:
TensorFlow Lite model incorporates both weights and model code itself. You need to load Keras model(with weights) and then you will be able to convert into tflite model.
Get a copy of authors' repo, and execute get-networks.sh. You need only data/lp-detector/wpod-net_update1.h5
for license plates detector so you can stop download earlier.
Dive a bit into code and you can find prepared load model function at keras utils.
After you get a model object, you can convert it into tflite.
Python3, TF2.4 tested:
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"defload_model(path,custom_objects={},verbose=0):
#from tf.keras.models import model_from_json
path = splitext(path)[0]
withopen('%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)
Good luck!
Post a Comment for "How To Convert Just A H5 File To A Tflite File?"