Tensorflow lite for sparkfun edge micr-controller, Didn't find op for builtin opcode 'CONV_2D' version 2 and 3

536 Views Asked by At

i am trying to use my TFlite Model with sparkfun edge (Apollo 3) microcontroller to recognize simple tunes like (do re mi fa ....) from Piano App i used the following python code with tensorflow v2

from tensorflow.keras import layers......

model = tf.keras.Sequential([
layers.InputLayer(input_shape=(2048,)),
layers.Reshape(target_shape=(1,2048,1)),
layers.Conv2D(8,(1,8),strides=(1,8)), 
layers.MaxPool2D((1,2),strides=(1,2)), 
layers.Conv2D(8,(1,8),strides=(1,8)), 
layers.MaxPool2D((1,2),strides=(1,2)),
layers.Reshape(target_shape=(64,)) ,
layers.Dense(8,activation="softmax")  
])
model.build(input_shape=(2048,))
model.compile(optimizer="adam",loss="binary_crossentropy")

i train the model and convert it with the following code

converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]
model_tflite = converter.convert()
open('model.tflite', "wb").write(model_tflite)

!apt-get  install xxd
!xxd -i 'model.tflite' > 'model.cc'
!cat 'model.cc'

i got the following debug output from Micro-controller:


setup_NN invoked ///
Model TFLITE_SCHEMA_VERSION OK ///
interpreter OK ///
AllocateTensors OK ///
________________

in_dim= 2 ///
input_type = kTfLiteFloat32 ///
in_size[0]= 1 ///
in_size[1]= 2048 ///
________________

out_dim= 2 ///
output_type = kTfLiteFloat32 ///
out_size[0]= 1 ///
out_size[1]= 8 ///
________________

Setup OK

Loop funktion inoked

**Didn't find op for builtin opcode 'CONV_2D' version '2'**
Invoke failed
___________________

when i changed the

converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS]

to 
    converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
with adding a 
representative_dataset function 

i got error : Didn't find op for builtin opcode 'CONV_2D' version '3'

i think sparkfun edge MC accept float32 as input , do i have to try with tensorflow.compat.v1 insted of v2 ? can you please point out where is wrong or just show me a working example ?

it is good to say that another model like sine_model with only fully connected layers + activations worked fine with me (in float32), but i really need the conv layers, i know it is better to use Conv1D but i have read somewhere that it is not supported

0

There are 0 best solutions below