From: https://stackoverflow.com/questions/50443411/how-to-load-a-tflite-model-in-script
Handles the case of multiple inputs and outputs.
interpreter = tf.lite.Interpreter(model_path=mfile)
interpreter.allocate_tensors()
# get input and output layer handles
input_details = sorted(interpreter.get_input_details(), key=lambda x:x['name'])
output_details = sorted(interpreter.get_output_details(), key=lambda x:x['name'])
phase = P[frame]
modelidx = int( phase * 50 ) % 50
Vin = X[np.newaxis,frame]
interpreter.set_tensor(input_details[modelidx]['index'], Vin)
interpreter.invoke()
Vout = interpreter.get_tensor(output_details[modelidx]['index'])
The constant input arrays need to be dependent on an Input
so that they will end up in the middle of the dependency tree.
L_Xmean = L.Lambda( lambda x : K.ones_like(x) * means.Xmean[np.newaxis], name=f'{prefix}_Xmean' )(inputX)
from tensorflow.keras.utils import plot_model
plot_model(model, to_file='network.png')