libfann / fann

Official github repository for Fast Artificial Neural Network Library (FANN)
GNU Lesser General Public License v2.1
1.59k stars 380 forks source link

Compiling FANN for MCUs #77

Closed tomfisher closed 6 years ago

tomfisher commented 8 years ago

Hi,

Is it possible to compile FANN for some MCUs such as ARM-Cortext M0? We just want to use the recognition part on MCU after a model has been trained on PC side.

Thanks.

jpdominguez commented 8 years ago

Yes, it is. Our research group has already deployed a ANN in a STM32F411 microcontroller (which has been previously trained on the PC) and it is working properly.

The only thing that you need to be careful with is to use the fixed point version of the library if your MCU does not have FPU. Also, if you are compiling the library for a MCU, try to reduce it as much as you can (removing training functions if you are doing the training step on the PC, etc.).

I hope this helps. We are now writting a paper for the Neurocomputing Journal in which we describe some tests that we have performed using the library on the microcontroller and the results that we have obtained. The preprocessing step and the network architecture are both studied in "Performance Evaluation of Neural Networks for Animal Behaviors Classification: Horse Gaits Case Study" (E. Cerezuela-Escuedero, et al., 2016).

tomfisher commented 8 years ago

Thanks a lot for your reply. I'll read your paper.

I am wondering and will be grateful if it's possible to share your reduced code.

agaelema commented 8 years ago

It would be very interesting share the code or some example

charlie34 commented 7 years ago

Yes you could share your code with us!!

spsancti commented 7 years ago

I tried to do it with mbed and FRDM-KL25Z. There is too little RAM to store nets of sufficient sizes, however, I could make XOR example work. Probably, I'll switch to some more hi-end MCU later.

agaelema commented 7 years ago

Do you remember how much memory is necessary? Generally the compiler show this value.

spsancti commented 7 years ago

I'm talking about RAM not flash. Basically, you need at least 4 bytes per each weight, plus some overhead in neurons. With fully connected net you have NxM weights between layers N and M. With mbed, SD card lib and fann basic examples, it's about 8 kB of flash used.

agaelema commented 7 years ago

Yes, I was referring to RAM memory, the major "problem". Generally after the compilation the IDE shows the total amount of flash and RAM needed.

spsancti commented 7 years ago

The RAM shown in IDE doesn't consider dynamically allocated RAM when loading net. I'd expect slightly more RAM to store the net than size of net file.

agaelema commented 7 years ago

@spsancti Do you need to change many things in the example?

spsancti commented 7 years ago

Well, here it is: https://developer.mbed.org/users/spsancti/code/neurorace-jr/ I tried it with FRDM-K64F and it works. Hope this helps.

troiganto commented 6 years ago

Since all questions here seem to be solved, can we close this issue?