Reputation: 11
I was trying to quantize a TF model into a TFLite model to deploy it on my ESP32 by calling the dataset through tf.keras.preprocessing.image_dataset_from_directory()
and used images_batch and labels_batch to iterate in the representative dataset()
function. But, I am getting the error: 'EndVector() takes 1 positional argument but 2 were given' and unable to rectify it.
Can someone please help me out?
TFlite convertor code:
converter = tf.lite.TFLiteConverter.from_saved_model(MODEL_DIR)
def representative_dataset():
for image_batch, labels_batch in train_ds:
yield [image_batch]
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
converter.representative_dataset = representative_dataset
model_tflite = converter.convert()
open('modelwithquant.tflite', "wb").write(model_tflite)
Upvotes: 0
Views: 1817
Reputation: 21
Downgrading flatbuffer seems to help:
pip install --upgrade flatbuffers==1.12
Upvotes: 2
Reputation: 111
Assuming train_ds
is tensorflow dataset:
Try changing this to:
def representative_dataset():
for image in train_ds.batch(1).take(100):
yield [image]
Representative dataset should generally yield a single representative input.
Upvotes: 0