cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to save or export knowledge which is learned while runtime?

mxo
Associate III

hello,

Now I'm trying to implement ML library created by NanoEdgeAI Studio to our STM32C0 target board.

My anomaly detection ML looks work fine at this time, but I wonder that every time after boot the system I have to learn normal case.

For our application, sometimes the system will shutdown while the work flows.

I also have tried 'Embedded Knowledge' option, but it's not as well so far.

So I want to save knowledge after learning while runtime on Real-target, and then it may work fine while the same work flows.

When the work to flow changed, then reset (or re-initialize) knowledge and learn normal case in work-setup procedure.  hmm, sounds good.

Is this possible?

BR, 

mxo

1 ACCEPTED SOLUTION

Accepted Solutions
Julian E.
ST Employee

Hello,

 

Your solution is great, thank you for the suggestion!

 

Regarding your questions, when you include the library neai.a, "neai" will appear both in FLASH and RAM. What we add in the linker script (.ld) is the KEEP:

 

.neai :
{
  _sneai_knowledge = .;	/* Start address of .neai section */
  KEEP(*(.neai))          /* Keep my variable even if not referenced */
  _eneai_knowledge = .;	/* End address of .neai section */
} >RAM

 

 It guarantees that the symbols are present, and it is also used to determine the start and end address of .neai section:

 

extern void *_sneai_knowledge;
extern void *_eneai_knowledge;

 

If you have other suggestion, please share it with us.

 

Best regards,

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

8 REPLIES 8
Julian E.
ST Employee

Hello,

 

I attached an example to save the knowledge and reuse it. 

Additionally, you can find information in the documentation:

AI:NanoEdge AI Library for anomaly detection (AD) - stm32mcu

 

Do not hesitate to contact me again if you need further assistance.

 

Best regards,

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.

Hello @Julian E. 

Thank you for your assistance, and then I want to ask some more for my understandings.

 

I found that the section ".neai" as you mentioned in my libneai.a is already implemented in both FLASH and RAM.

(note that I implemented library with 'Embedded Knowledge' option.)

mxo_0-1714528008050.png

 

Q1.

Is step #2 of PDF instruction means that create another copy of .neai section in RAM, or only give name at existing .neai section ?

mxo_1-1714533711855.png

In the Wiki page, fixed address is given to .neai section in RAM, instead giving name.

I think giving name is better..

 

Q2.

According to step #3 & #4 of PDF instruction, knowledge is held as uint32_t array and it is ensized with WORD_SIZE to copy to/from FLASH, but is it right?

In conclusion, I guess that only an entire .neai section should be copied between FLASH & RAM.

Or (also concern with Q1), .neai in FLASH should be kept as is and only save copy of .neai RAM to disignated FLASH page, how is this?

 

Anyway, the solution is exactly what I want!

(quite little another thing but, the line of .neai section in the size list is deleted or hide between PDF pages.. oh, where is 136 sized??)

B.R.

mxo

mxo
Associate III

Hello again,

I have just verified about .neai section.

Linker script is as following..

  /* customize for NanoEdgeAI ML knowledge implementation */
  .neai :
  {
  	_neai_knowledge = .;
  	KEEP(*(.neai))
  	_eneai_knowledge = .;
  } >RAM

then my main.c has..

extern void *_neai_knowledge;	// for knowledge save & restore - section .neai start address
extern void *_eneai_knowledge;	// - section .neai end address
#define NEAI_SectionSize	((unsigned int)&_eneai_knowledge - (unsigned int)&_neai_knowledge)

and my library is..

mxo_0-1714543195257.png

and take look after load..

mxo_1-1714543280220.png

and, OK, print section size to consle..

mxo_2-1714543387970.png

 

I believe this is better while determing section size.

B.R.

mxo

Julian E.
ST Employee

Hello,

 

Your solution is great, thank you for the suggestion!

 

Regarding your questions, when you include the library neai.a, "neai" will appear both in FLASH and RAM. What we add in the linker script (.ld) is the KEEP:

 

.neai :
{
  _sneai_knowledge = .;	/* Start address of .neai section */
  KEEP(*(.neai))          /* Keep my variable even if not referenced */
  _eneai_knowledge = .;	/* End address of .neai section */
} >RAM

 

 It guarantees that the symbols are present, and it is also used to determine the start and end address of .neai section:

 

extern void *_sneai_knowledge;
extern void *_eneai_knowledge;

 

If you have other suggestion, please share it with us.

 

Best regards,

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.

Hello,

Thank you for reviewing.

 

Now I'm almost clear about them except following one..

mxo_0-1715040644003.png

Is this definition comes from some FLASH limitation or only a mistake?

We are now trying to export and restore .neai section through serial communication port with binary dump method we have, and the dump size is only "NEAI_KNOWLEDGE_SIZE".

I believe that we're on right way at least while our trials, but I want to know if you have any other reasons about saving to FLASH.

B.R.

mxo

Hello @mxo,

Here are some elements that may help you:

  • We read and write in flash using a code similar to this one with a STM32F401:

STM32CubeF4/Projects/STM32F401-Discovery/Examples/FLASH/FLASH_EraseProgram/Src/main.c at master · STMicroelectronics/STM32CubeF4 · GitHub

  • word_size is the size of word in FLASH, which is 4 bytes I believe.
  • Info on page 45 of this document:

STM32F401xB/C and STM32F401xD/E advanced Arm®-based 32-bit MCUs - Reference manual

JulianE_0-1715083017635.png

Best regards,

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.

Hello @Julian E. 

Thank you for your assistance and they lead our application better enough.

Later, I will verify FLASH R/W issue, that I think this is another issue and recently it dosen't matter about our application so far.

 Again, thank you very much.

Best Regards.

mxo

Hello,

Your issue with the FLASH R/W is probably due to the WORDSIZE not being defined.

 

Good luck with your project and do not hesitate to contact us again if you encounter any other issues.

Best regards,

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.