MG24 and Edge Sense Library in Arduino Studio - multiple definition of TensorFlow Lite library

Hello all !

I’ve just bought the Xiao MG24 3-pack (amazing little board for wearables !) from Amazon, so I could start to tinker with the included IMU and microphone .

To get started, I decided to do a basic gesture detection application - make a serie of movements, the board outputs ‘right moves’ or ‘wrong moves’ - a quite basic machine learning application.

Since I have no experience with ML at all, i decided to make all the capture/conditioning/training part of the process using the Edge Impulse site (https://edgeimpulse.com/) - it does it all by connecting the board directly to the site via a tailored serial capture app. I did a small Arduino sketch to spit IMU values directly to the serial, the program captures it, sends to the site. In the end, after all the processing, it generates a tailored Arduino lib (.zip file) with all the support libraries - TensorFlow lite included - and functions that I just call, passing the same set of IMU readings, and in makes the inference to say if it fits the generated model (right moves) or not (wrong moves).

And that’s where I having a problem… since i intend to pass this result to another computer via bluetooth, I chose to compile the inference sketch (which includes the Edge Impulse library) with the ‘Silabs BLE’ stack - which includes a pre-compiled version of TensorFlow lite too. And that prevents compiling, when the linker detects multiple definitions of the TFLite functions.

The generated Edge Impulse library specifficaly for my trained set is called ‘MG24_Sense_inferencing’ , so my code (resumed to the important parts) is very simple:

#include <MG24_Sense_inferencing.h>
#include <LSM6DS3.h>
//#include <Wire.h>
//Create a instance of class LSM6DS3
LSM6DS3 myIMU(I2C_MODE, 0x6A);    //I2C device address 0x6A

float samples[total_buffer_size];

void Setup() {
  …initializes the IMU and inference library
}

void loop() {

  Serial.println(“Acquiring samples in 3 seconds:)”;
  delay(3000);

  for (i=0; i<total_buffer_size; i=i+6) {
    samples[i] = readFloatAccelX();
  // do it 5 more times for acceleration and gyroscope values
  }

  // Call the inferencing function inside Edge Impulse library
  // passing the buffer (false = no debug)

  EI_IMPULSE_ERROR res = run_classifier(&buffer, &result, false);
  …
  // best_match_index is the result with max confidence returned by the model
  const char *predicted_label = ei_classifier_get_label(best_match_index);
  if (strcmp(predicted_label, “good-move”) == 0) {
    Serial.println(“OUTPUT: good”);
  }
}

And that’s it. But when I try to compile it, as soons as it generates all the .o files and the linker starts working, I get a lot of ‘already defined function’ errors - basically for all the functions in the TFLite library - since it is included both in the MG24_Sense_inferencing lib, and in the pre-compiled library used by the Silabs BLE stack (inside gsdk.a ? - not sure). Two examples:

… linker starts …

ld.exe:C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\variants\xiao_mg24/ble_silabs/gsdk.a(unidirectional_sequence_lstm.o):in function tflite::Register_UNIDIRECTIONAL_SEQUENCE_LSTM()‘: /Users/tajozsi/Library/Arduino15/packages/SiliconLabs/hardware/silabs/3.0.0/package/gen/aiml_2.0.0/third_party/tflite-micro/tensorflow/lite/micro/kernels/cmsis_nn/unidirectional_sequence_lstm.cc:672: multiple definition of tflite::Register_UNIDIRECTIONAL_SEQUENCE_LSTM()’; C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\tensorflow\lite\micro\kernels\objs.a(unidirectional_sequence_lstm.cpp.o):c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels/unidirectional_sequence_lstm.cpp:585: first defined here

ld.exe:C:\Users\Luis\AppData\Local\Arduino15\packages\SiliconLabs\hardware\silabs\3.0.0\variants\xiao_mg24/noradio/libtflm.a(kernel_util.cc.obj):in function tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)‘: C:/Users/anmahade/src/gsdk/extension/aiml-extension/third_party/tflite-micro/tensorflow/lite/micro/kernels/kernel_util.cc:63: multiple definition of tflite::micro::GetMutableEvalInput(TfLiteContext const*, TfLiteNode const*, int)’; C:\Users\Luis\AppData\Local\arduino\sketches\05E61CED255EDA90751A781933D93C90\libraries\MG24_Sense_inferencing\edge-impulse-sdk\tensorflow\lite\micro\kernels\objs.a(kernel_util_micro.cpp.o):c:\src\Arduino\libraries\MG24_Sense_inferencing\src\edge-impulse-sdk\tensorflow\lite\micro\kernels/kernel_util_micro.cpp:60: first defined here

and it repeats for all TFlite functions. The paths including ‘tajozsi’ and ‘anmahade’ are indicators maybe that the functions were pre-compiled?

So, after all that, my question is - is there a to compile everything, i.e.the generated Edge Impulse library and the pre-compiled BLE library, excluding the pre-compiled TFLite lib in the Silabs BLE stack and making it use the TFLite functions included in the Edge Impulse library, since they are the same?

Thanks!

Luis.