cancel
Showing results for 
Search instead for 
Did you mean: 

ML algorithms used in nanoedge MC classification

martur
Associate

Hi,

1) I Am currently exploring the capabilities of NanoEdge for a project involving multiclass classification, and I am eager to learn more about the specific machine learning algorithms utilized within the NanoEdge framework. I feel as though I am using a black box to generate the model, and I would like to know if it is possible to make optimizations during the learning step.

2) After generating the model, I used the time.h library to compute the inference time of the model in STM32CubeIDE by creating a timer before and after calling the neai_classification function. However, the result is always 0, even though the model produces the correct classification results. This may be because the inference time is very small. Are there other solutions to accurately measure the inference time?

 

Thank you very much for your help 

1 ACCEPTED SOLUTION

Accepted Solutions
Julian E.
ST Employee

Hello @martur ,

 

Indeed, the model is quite a black box, but it is made as is, so I won't be able to help you on that.

 

You can measure the execution time of a function using the Arm DWT cycle counter. This is possible with every STM32, except those having a Cortex-M0 or M0+. It allows a very accurate result, since you will get the the number of MCU clock cycles necessary for the function execution. From this value, you can easily calculate the time in ms or us. It is possible that a NanoEdgeAI inference takes less than 1ms!

 

You can use a code kind of like this:

// Function to initialize the DWT cycle counter
void DWT_Init(void) {
    // Enable TRC (Trace Control)
    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    // Reset the cycle counter
    DWT->CYCCNT = 0;
    // Enable the cycle counter
    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
}
 
// Function to measure execution time using DWT
uint32_t Measure_Execution_Time(void (*func)(void)) {
    uint32_t start, end;
    // Start the cycle counter
    start = DWT->CYCCNT;
    // Call the function
    func();
    // Stop the cycle counter
    end = DWT->CYCCNT;
    // Calculate the elapsed time
    return (end - start);
}
 
// Example function to measure
void Example_Function(void) {
    // Some code to measure
}
 
int main(void) {
    HAL_Init();
    DWT_Init();
    uint32_t cycles = Measure_Execution_Time(Example_Function);
    // Print or use the cycles value
    printf("Execution time: %lu cycles\n", cycles);
    while (1) {
        // Main loop
    }
}

 

 

Have a good day

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Julian E.
ST Employee

Hello @martur ,

 

Indeed, the model is quite a black box, but it is made as is, so I won't be able to help you on that.

 

You can measure the execution time of a function using the Arm DWT cycle counter. This is possible with every STM32, except those having a Cortex-M0 or M0+. It allows a very accurate result, since you will get the the number of MCU clock cycles necessary for the function execution. From this value, you can easily calculate the time in ms or us. It is possible that a NanoEdgeAI inference takes less than 1ms!

 

You can use a code kind of like this:

// Function to initialize the DWT cycle counter
void DWT_Init(void) {
    // Enable TRC (Trace Control)
    CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
    // Reset the cycle counter
    DWT->CYCCNT = 0;
    // Enable the cycle counter
    DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
}
 
// Function to measure execution time using DWT
uint32_t Measure_Execution_Time(void (*func)(void)) {
    uint32_t start, end;
    // Start the cycle counter
    start = DWT->CYCCNT;
    // Call the function
    func();
    // Stop the cycle counter
    end = DWT->CYCCNT;
    // Calculate the elapsed time
    return (end - start);
}
 
// Example function to measure
void Example_Function(void) {
    // Some code to measure
}
 
int main(void) {
    HAL_Init();
    DWT_Init();
    uint32_t cycles = Measure_Execution_Time(Example_Function);
    // Print or use the cycles value
    printf("Execution time: %lu cycles\n", cycles);
    while (1) {
        // Main loop
    }
}

 

 

Have a good day

Julian


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.