In [22]:
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_quant_model = converter.convert()

open("converted_model.tflite", "wb").write(tflite_quant_model)
Out[22]:
2299048
In [23]:
interpreter = tf.lite.Interpreter(model_content=tflite_quant_model)
interpreter.allocate_tensors()
In [24]:
input_details = interpreter.get_input_details()
output_details= interpreter.get_output_details()

interpreter.resize_tensor_input(input_details[0]['index'], (32, 224, 224, 3))
interpreter.resize_tensor_input(output_details[0]['index'], (32, 5))
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details= interpreter.get_output_details()
In [25]:
print("== Input details ==")
print("shape:", input_details[0]['shape'])
print("type:", input_details[0]['dtype'])
print("\n== Output details ==")
print("shape:", output_details[0]['shape'])
print("type:", output_details[0]['dtype'])
== Input details ==
shape: [ 32 224 224   3]
type: <class 'numpy.float32'>

== Output details ==
shape: [32  1]
type: <class 'numpy.float32'>