cancel
Showing results for 
Search instead for 
Did you mean: 

how it works 1_class library ?

AkaPaDa_18
Associate III

Hello ,

I'm trying to figure out how the 1_class library works. In the Emulator tab of the NanoedgeAI Studio software, I can see that the sensor indicates that the input pattern is detected as an outlier (outside the class considered), as shown in the following image:

AkaPaDa_18_0-1701961614101.png

 

But when embedded on microcontrollers, according to my code the orange LED should be flashing, but it's the green LED. I can't figure it out. Is my code correct? How can I retrieve the function output, which should be 0 for belongs to the class or 1 for outside of the class?

Thanks for your help.

A part of my code :

/*________________1_class_____________________*/

neai_state = neai_oneclass_init(knowledge);

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

if (drdy) {

/* Reset data ready variable */

drdy = 0;

/* Read watermark flag */

iis3dwb_fifo_status_get(&dev_ctx, &fifo_status);

if (fifo_status.fifo_th) {

num = fifo_status.fifo_level;

if (data_left > num) {

data_left -= num;

}

else {

num = data_left;

data_left = 0;

}

iis3dwb_get_buffer_from_fifo(num);

if (data_left == 0) {

/* Stop FIFO mode, set it in BYPASS mode */

iis3dwb_fifo_mode_set(&dev_ctx, IIS3DWB_BYPASS_MODE);

 

#if NEAI_MODE

uint32_t cycles_cnt = 0;

 

/* ############################## Partie Mode 1-class #######################################################*/

/*ici*/

KIN1_ResetCycleCounter();

neai_similarity = neai_oneclass(neai_buffer, &oneclass_result);

cycles_cnt = KIN1_GetCycleCounter();

if (neai_similarity == 0)

{

/*HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);

HAL_Delay(1000);

HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);*/

printf("Regular");

HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);

HAL_Delay(1000);

 

/*HAL_GPIO_WriteMultipleStatePin(LED1_GPIO_Port, LED1_Pin, LED2_Pin);*/

}

if(neai_similarity == 1){

/*

HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET); */

printf("Abnormal");

HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);

HAL_Delay(1000);

 

}

neai_time = (cycles_cnt * 1000000.0) / HAL_RCC_GetSysClockFreq();

 

printf("\n");

printf("NEAI learn return: %d.\n", neai_similarity);

1 ACCEPTED SOLUTION

Accepted Solutions

Hi AkaPaDa_18,

 

In your if conditions, you should replace neai_similarity by oneclass_result, to make the orange LED blink when an outlier is detected.

You should also rename the neai_similarity variable by neai_state. Similarity has no meaning in 1-class classification.

 

Best regards,

Antoine

View solution in original post

4 REPLIES 4
ABOIS.1
ST Employee

Hello AkaPaDa_18,

 

In your code, the result of the outlier detection is stored in oneclass_resultNanoEdgeAI functions return a status variable.

 

For more details, please check the documentation:

https://wiki.st.com/stm32mcu/wiki/AI:NanoEdge_AI_Library_for_1-class_classification_(1CC)

 

Best regards,

Antoine

 

Hi @ABOIS.1 ,

Thanks for your quick reply. I already check the documentation that your are mentioned. My preoccupation is that concerning the below code,  the orange LED (LED2) should blink instead of  the green LED (LED1).

AkaPaDa_18_0-1702291370947.png

 

Hi AkaPaDa_18,

 

In your if conditions, you should replace neai_similarity by oneclass_result, to make the orange LED blink when an outlier is detected.

You should also rename the neai_similarity variable by neai_state. Similarity has no meaning in 1-class classification.

 

Best regards,

Antoine

Wonderful!! it's works!!!

thanks, God Bless you