hi guys
I recently used the micromlgen library in python to convert the XGBoost model into c++ form.
When I burn the machine learning model file to esp32, there is no problem if the capacity of the machine learning model is around 1.0kb, but I will encounter an error when the capacity of the machine learning model is around 1.5kb, as shown below:
Here's what it looked like when it went wrong:
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55423:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d48f): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173b0)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55433:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d4a0): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173b4)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55460:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d4ac): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173b8)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55440:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d4d6): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173bc)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55445:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d4f7): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173c0)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55449:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d508): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173c4)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55456:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d52a): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173c8)
C:\Users\88693\Desktop\LAB這邊的水龍頭程式\Faucet_system20240218b/XGBoost_model20240218e.h:55460:(.text._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf[_ZN8Eloquent2ML4Port13XGBClassifier7predictEPf]+0x4d539): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal._ZN8Eloquent2ML4Port13XGBClassifier7predictEPf+0x173cc)
collect2.exe: error: ld returned 1 exit status
exit status 1
開發板 Node32s 編譯錯誤。
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This is the code::
#include "XGBoost_model20240218b.h"
#include "XGBoost_user_model20231106.h"
//esp32
const byte pinIRa_1 = A4;
const byte pinIRa_2 = A7;
const byte pinIRa_3 = A6; // 左
const byte pinIRa_4 = A5; // 右
#define buzzer 11 //蜂鳴器
const int buffer_size = 32; // 陣列大小
int PIRpillar_A_V=0;
int previous_PIRpillar_A_V = 0; // 用來存儲上一個PIRpillar_A_V的數值
float new_PIRpillar_A_V;
int PIRpillar_A_V_diff;
int PIRinitiative_A_V=0;
int previous_PIRinitiative_A_V = 0; // 用來存儲上一個PIRinitiative_A_V_A_V的數值
float new_PIRinitiative_A_V;
int PIRinitiative_A_V_diff;
int PIR_L_A_V=0;
int previous_PIR_L_A_V = 0; // 用來存儲上一個PIR_L_A_V的數值
float new_PIR_L_A_V;
int PIR_L_A_V_diff;
int PIR_R_A_V=0;
int previous_PIR_R_A_V = 0; // 用來存儲上一個PIR_R_A_V的數值
float new_PIR_R_A_V;
int PIR_R_A_V_diff;
bool Compare_values_switch = false;
float PIRpillar_A_V_array[buffer_size]; // 陣列宣告
float PIRinitiative_A_V_array[buffer_size];
float PIR_L_A_V_array[buffer_size];
float PIR_R_A_V_array[buffer_size];
int counter = 0; // 計數器
int data1[10000];
int data2[10000];
int data3[10000];
int data4[10000];
int vs = 0;
int num = 0;
int f = 0;
Eloquent::ML::Port::XGBClassifier classifier;
Eloquent::ML::Port::XGBClassifier_user classifier_user;
float features[128]; // 4個特徵,每個特徵有24個值
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(pinIRa_1, INPUT);
pinMode(pinIRa_2, INPUT);
pinMode(pinIRa_3, INPUT);
pinMode(pinIRa_4, INPUT);
delay(1000);
xTaskCreate(
taskOne, /* Task function. */
"TaskOne", /* String with name of task. */
10000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL); /* Task handle. */
xTaskCreate(
taskTwo, /* Task function. */
"TaskTwo", /* String with name of task. */
10000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL); /* Task handle. */
xTaskCreate(
taskThree, /* Task function. */
"TaskThree", /* String with name of task. */
10000, /* Stack size in bytes. */
NULL, /* Parameter passed as input of the task */
1, /* Priority of the task. */
NULL); /* Task handle. */
}
void loop()
{
// put your main code here, to run repeatedly:
//Serial.println("Hello from task 0");
PIRpillar_A_V = analogRead(pinIRa_1);
PIRinitiative_A_V = analogRead(pinIRa_2);
PIR_L_A_V = analogRead(pinIRa_3);
PIR_R_A_V = analogRead(pinIRa_4);
if(Compare_values_switch==false)
{
previous_PIRpillar_A_V = PIRpillar_A_V;
previous_PIRinitiative_A_V = PIRinitiative_A_V;
previous_PIR_L_A_V = PIR_L_A_V;
previous_PIR_R_A_V = PIR_R_A_V;
Compare_values_switch=true;
}
// 檢查新的PIRpillar_A_V是否大於小於上一個數值
if (PIRpillar_A_V > previous_PIRpillar_A_V or PIRpillar_A_V < previous_PIRpillar_A_V) {
PIRpillar_A_V_diff = (PIRpillar_A_V - previous_PIRpillar_A_V) * 8;
/*
Serial.println("1");
Serial.print("PIRpillar_A_V:");
Serial.println(PIRpillar_A_V);
Serial.print("previous_PIRpillar_A_V:");
Serial.println(previous_PIRpillar_A_V);
Serial.print("diff:");
Serial.println(diff);
*/
new_PIRpillar_A_V = previous_PIRpillar_A_V + PIRpillar_A_V_diff;
previous_PIRpillar_A_V = PIRpillar_A_V;
}
else{new_PIRpillar_A_V = previous_PIRpillar_A_V;}
// 檢查新的PIRinitiative_A_V是否大於小於上一個數值
if (PIRinitiative_A_V > previous_PIRinitiative_A_V or PIRinitiative_A_V < previous_PIRinitiative_A_V) {
PIRinitiative_A_V_diff = (PIRinitiative_A_V - previous_PIRinitiative_A_V) * 4;
new_PIRinitiative_A_V = previous_PIRinitiative_A_V + PIRinitiative_A_V_diff;
previous_PIRinitiative_A_V = PIRinitiative_A_V;
}
else{new_PIRinitiative_A_V = previous_PIRinitiative_A_V;}
// 檢查新的PIR_L_A_V是否大於小於上一個數值
if (PIR_L_A_V > previous_PIR_L_A_V or PIR_L_A_V < previous_PIR_L_A_V) {
PIR_L_A_V_diff = (PIR_L_A_V - previous_PIR_L_A_V) * 2;
new_PIR_L_A_V = previous_PIR_L_A_V + PIR_L_A_V_diff;
previous_PIR_L_A_V = PIR_L_A_V;
}
else{new_PIR_L_A_V = previous_PIR_L_A_V;}
// 檢查新的PIR_R_A_V是否大於小於上一個數值
if (PIR_R_A_V > previous_PIR_R_A_V or PIR_R_A_V < previous_PIR_R_A_V) {
PIR_R_A_V_diff = (PIR_R_A_V - previous_PIR_R_A_V) * 2;
new_PIR_R_A_V = previous_PIR_R_A_V + PIR_R_A_V_diff;
previous_PIR_R_A_V = PIR_R_A_V;
}
else{new_PIR_R_A_V = previous_PIR_R_A_V;}
PIRpillar_A_V_array[counter] = new_PIRpillar_A_V; // 將數值新增至第一個陣列
PIRinitiative_A_V_array[counter] = new_PIRinitiative_A_V; // 將數值新增至第二個陣列
PIR_L_A_V_array[counter] = new_PIR_L_A_V;
PIR_R_A_V_array[counter] = new_PIR_R_A_V;
counter++; // 計數器加1
/*Serial.print("Analog reading_01:");
Serial.print(PIRpillar_A_V);
Serial.print(" ");
Serial.print("Analog reading_02 :");
Serial.print(PIRinitiative_A_V);
Serial.println();*/
if (counter == buffer_size) { // 當兩個陣列都累積到24個值
// Fill the input buffer
for (int i = 0; i < 24; i++) {
features[i] = PIRpillar_A_V_array[i];
features[i + 24] = PIRinitiative_A_V_array[i];
features[i + 48] = PIR_L_A_V_array[i];
features[i + 72] = PIR_R_A_V_array[i];
}
// 顯示陣列中的數值
/*
for (int i = 0; i < buffer_size; i++) {
Serial.print(PIRpillar_A_V_array[i]);
Serial.print(", ");
}
Serial.print(";");
for (int i = 0; i < buffer_size; i++) {
Serial.print(PIRinitiative_A_V_array[i]);
Serial.print(", ");
}
Serial.print(";");
for (int i = 0; i < buffer_size; i++) {
Serial.print(PIR_L_A_V_array[i]);
Serial.print(", ");
}
Serial.print(";");
for (int i = 0; i < buffer_size; i++) {
Serial.print(PIR_R_A_V_array[i]);
Serial.print(", ");
}
Serial.println();
*/
/*
for (int i = 0; i < 96; i++) {
Serial.print(features_me[i]);
Serial.print(", ");
}
Serial.println();
*/
// Run the inferencing
//String predictionClass = classifier.predictLabel(features);
// Run the inferencing(XGBoost_model使用時)
int predictionClass = classifier.predict(features);
int predictionClass_user = classifier_user.predict(features);
counter = 0; // 將計數器歸零,清空陣列
memset(PIRpillar_A_V_array, 0, sizeof(PIRpillar_A_V_array));
memset(PIRinitiative_A_V_array, 0, sizeof(PIRinitiative_A_V_array));
memset(PIR_L_A_V_array, 0, sizeof(PIR_L_A_V_array));
memset(PIR_R_A_V_array, 0, sizeof(PIR_R_A_V_array));
if(predictionClass == 5)
{
Serial.println("合掌搓洗");
}
else if(predictionClass == 2)
{
Serial.println("十指交錯搓洗");
}
else if(predictionClass == 3)
{
Serial.println("搓左手背");
}
else if(predictionClass == 4)
{
Serial.println("搓右手背");
}
if(predictionClass_user == 1)
{
Serial.println("蔡");
}
else
{
Serial.println("其他人");
}
delay(500);
}
}
void taskOne(void *parameter)
{
for (int i = 0; i < 10; i++)
{
Serial.println("Hello from task 1");
delay(100);
}
Serial.println("Ending task 1");
vTaskDelete(NULL);
}
void taskTwo(void *parameter)
{
for (int i = 0; i < 100; i++)
{
Serial.println("Hello from task 2");
delay(1000);
}
Serial.println("Ending task 2");
vTaskDelete(NULL);
}
void taskThree(void *parameter)
{
for (int i = 0; i < 100; i++)
{
Serial.println("Hello from task 3");
delay(1000);
}
Serial.println("Ending task 3");
vTaskDelete(NULL);
}
This is the model:
XGBoost_model20240218b.h (1.6 MB)
XGBoost_user_model20231106.h (1018.4 KB)
May I ask what kind of question this is?