While trying 'Validate on Desktop' for tflite model, we are getting the error : "TOOL ERROR Didn't find op for built-in opcode "FULLY_CONNECTED" for version '9' Registration failed".
While trying 'Validate on Desktop' for tflite model, we are getting the error : "TOOL ERROR Didn't find op for built-in opcode "FULLY_CONNECTED" for version '9' Registration failed".
First, the raised error is due to the version of the TFLite interpreter which is embedded in the X-CUBE-AI pack to perform the evaluation of the generated c-model. In X-CUBE-AI 5.2, the version of the TF Lite interpreter is TF2.3. I suppose that to generate the TFLite file, you have used a more recent version +2.4. In this case, the generated TFLite file is generated with a version 9 of the FULLY_CONNECTED operator.
Other point, according the referenced link to train and to convert the model, the OPTIMIZE_FOR_SIZE (no more documented since TF2.3)
should be not used. Because it is not really supported in X-CUBE-AI and particularly for a tiny run-time, including also tensorflow lite for micro-controller. In this case, only the weights are quantized, and the C run-time requires to implement the hybrid kernels to manage the weights in int8 and the activations in float. This option is only interesting to reduce the size of the deployed TFLite file, but it requests a runtime with extra memory and computing resources to execute it (like Mobile device with Android or iOS). Only the following Python code should be used to create a TF Lite float version of the Keras model. In this case, with TF +2.4, the generated TF Lite will be generated with version 1 of the FULLY_CONNECTED operator, fully compliant with X-CUBE-AI 5.2. You can note that in this case, the Keras model (h5 file) can be directly imported in X-CUBE-AI and the generated c-model will be exactly the same.
Last point, for info, the generated c-model for the TF Lite model (with FC v9) is valid and can be used. If you want to valid it, with your own data, the following command line can be used to avoid to execute the original model thanks the --no-exec-model option: