Building TFLM library for Cortex-M4 Nucleo-L4R5ZI and Mbed Studio

721 views
Skip to first unread message

Martin Cavallo Percovich

unread,
Sep 18, 2021, 11:43:00 AM9/18/21
to SIG Micro, jonat...@gmail.com
Hi everyone!

I am walking my first steps throught TFLM. I want to develop an tinyML applitcation to run on Cortex-M4 Nucleo-L4R5ZI board. I would like to write my code using Mbed Studio.  So, I am working besed on the following resources:
  • O'Reilly Tiny ML book. Particularly with sections...
    • Chapter 13:TensorFlow Lite for Microcontrollers, Build Systems, pages 361-362
    • Chapter 6: The "Hello World" of TinyML:Deploying to Microcontrollers, ST Microelectornics STM32F746G Discovery Kit, pages 124 to 126.
  • Arm Mbed tutorial 
The problem is that these resources and every tutorial show examples cloning from the old tensorflow lite github repository. Despite of @Advait Jain message on 19 may 2021, with subject "Update on the TFLM repository transition", where it says "The directory structure within the TFLM repository is identical to the TensorFlow  repository so switching should only involve changing which GitHub repository you are cloning/forking." , my experience shows that this is not real. Let me explain below.

I am working on Windows 10, but following recomendation in O'Reilly TinyML book in page 361 where it says "What if you’re running on a Windows machine or want to use an IDE like Keil, Mbed, Arduino, or another specialized build system? That’s where the project generation comes in. You can generate a folder that’s ready to use with the Mbed IDE by running the following command line from Linux:",  I have mounted an Ubuntu 18.04 LTS virtual machine with Virtual Box.

Here I detail the steps I have followed and why I am a bit confused.

  1. Download the TensorFlow Lite source code with: git clone https://github.com/tensorflow/tflite-micro.git
  2. First confusing point: Tutorials say that exists the following directoy: tensorflow/tensorflow/lite/micro/mbed/ but there is no mbed folder. Instead I find cortex_m_generic folder that I think it is what I need.
  3. Following the Readme file in  cortex_m_generic, I executed the make command for building TFLM library:  make -f tensorflow/lite/micro/tools/make/Makefile TARGET=cortex_m_generic TARGET_ARCH=cortex-m4 OPTIMIZED_KERNEL_DIR=cmsis_nn microlite
  4. Second confusing point: O'Reilly TinyML says "You should now see a set of source files in tensorflow/lite/micro/tools/make/gen/disco_f746ng_x86_64/prj/micro_speech/mbed/, along with all the dependencies and project files you need to build within the Mbed environment." However, there is no prj folder in my case. Please check in the picture bellow. What I have is tensorflow/lite/micro/tools/make/gen/cortex_m_generic_cortex-m4_defaults
    1. core folder
    2. kernels folder
    3. third_party foldergenerated.png
So, how must I continue working?? Could anyone tell me how the workflow or pipeline goes on until get ready for writing applicaction code with Mbed Studio??

Thanks in advance and sorry if it a bit large the message, but I try to be as clear as possible.

I hope to get an early response.

Best Regards, 
Martin

Martin Cavallo Percovich

unread,
Sep 18, 2021, 3:52:24 PM9/18/21
to SIG Micro, jonat...@gmail.com
I have an error in point 4.  What I have is tensorflow/lite/micro/tools/make/gen/cortex_m_generic_cortex-m4_defaults and is verified in the picture are: genfiles, lib and obj folders.

I do not have a lot of experience working with libraries, but:
  • genfiles folder looks like it has just 3 examples: hello_world, magic_wand and person_detection
  • lib folder contains libtensorflow-microlite.a that I think it is the library
  • obj folder that I understand contains objective files during compilation.
Should I use only  libtensorflow-microlite.a file???

--
You received this message because you are subscribed to the Google Groups "SIG Micro" group.
To unsubscribe from this group and stop receiving emails from it, send an email to micro+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/micro/60c104ac-bb48-469f-86a6-5e4fe6a2770bn%40tensorflow.org.


--
Saludos,

Martin Cavallo
Ing. Tecnológico Electrónico

Fredrik

unread,
Sep 20, 2021, 6:50:07 AM9/20/21
to Martin Cavallo Percovich, SIG Micro, jonat...@gmail.com
Hi Martin,

Good to see you're looking into the TFLM project! I'll try my best to help out. I'd recommend either of these approaches.

1. The generic Arm Cortex-M target produces a lib that you can compile/link your example towards. libtensorflow-microlite.a is the name of that lib and contains only TFLM code (kernels, interpreter, memory allocator etc.), no startup code nor a main function. This build recipe is not related to Mbed project generation. I hope this answers the confusion on bullet 2.
2. There are general porting guidelines available here. You can also follow this ticket for more context. That'll describe how to go about porting TFLM to your target.
3. Here is an example building an image recognition example, using TFLM, with Mbed tooling. It should be fairly simple to port to your needs. Arm Mbed tutorial  looks slightly outdated to me.
4. This option may not be what you're looking for, but I'll throw it in here just in case... If you'd like to try your environment on an emulated platform, checkout the Corstone-300 FVP, and e.g. the last proposed make command here. Another option for running an emulated platform is Renode, check this link.

Let me know how it goes.

Cheers!
Fredrik


Martin Cavallo Percovich

unread,
Sep 20, 2021, 11:15:54 AM9/20/21
to Fredrik, SIG Micro, jonat...@gmail.com
Hi Fredrik!

Thank you so much for your support. I have read a bit fast your response and recomendations, but I think it will help me a lot. I will treat these points in the next weeks, with calm.

As a quick solution, I downloaded tensorflow 2.5.1 repository and in this way I could follow the tutorials porting TFLM on Arduino Nano 33 BLE Sense board. But I am still interested in porting TFLM on Nucleo-L4R5ZI, and of course using the last version of TFLM.

Keep in touch and thanks again.

Cheers,
Martin
Reply all
Reply to author
Forward
0 new messages