Did anyone manage to train a tflite model that can make predictions on batches of images successfully on Openmv H7plus 4.7 release?Wanting to see if I can get a performance increase on a small model of mine by predicting in batches rather than in a serial manner.I am trying and failing miserably when loading the model created with tensorflow using the same parameters for quantization that I use for the normal serial model with a different representative_data set construct.
def representative_data_gen():
samples_per_class = rep_data_samples_per_class
class_counts = {j: 0 for j in range(NUM_CLASSES)}
batch_imgs = \[\]
for img, label in rep_data:
true_class = np.argmax(label)
if class_counts\[true_class\] >= samples_per_class:
continue
batch_imgs.append(img)
class_counts\[true_class\] += 1
if len(batch_imgs) == BATCH_SIZE:
yield \[np.stack(batch_imgs, axis=0).astype(np.float32)\]
batch_imgs = \[\]
\# Pad last incomplete batch with duplicates
if batch_imgs:
while len(batch_imgs) < BATCH_SIZE:
batch_imgs.append(batch_imgs\[-1\])
yield \[np.stack(batch_imgs, axis=0).astype(np.float32)\]
… # Convert to quantized TFLite
converter = tf.lite.TFLiteConverter.from_keras_model(fixed_model)
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_data_gen
tflite_model = converter.convert()
Can it be that ml doesn’t support batch inference?
Tried both loading from ROM FS and Flash with load_to_fb True and False
tf_mod = ml.Model(F)
Model size: 39096 bytesAllocated RAM: 6016 Free RAM: 4331264
Load failed: Failed to allocate tensors
Allocated RAM: 4104384 Free RAM: 232896
note batch tflites generated from h5 files from which I generate also serial tflite models that run successfully so there are no operations in the model which the openmv cannot handle in the model.