How to deploy model to Raspberry Pi Zero

Hi!

We really love Edge Impulse and managed to collect the data and train the model fine so far.

Now, we would like to deploy our model to the Raspberry Pi Zero and have seen that it is not officially supported. We could not get the command line tools to work, so what I tried next was to get the C++ SDK working.

I am unable to compile the C-library I exported directly on the Raspberry Pi. The execution just stops at some random point (maybe out of memory??)

It would probably make more sense to compile the model on my Mac with the Raspberry Pi Zero as the target for the model file. How would I do that?

Or is there a better approach that you would suggest we try?

Thanks a lot!

These instructions are updated after getting it working

What worked for me was to follow the custom C++ porting guide here:

Download your model from the Web interface as a C++ library.
Copy and extract the folder on the Pi.
Add your data as in the tutorial
Add the Makefile from the Tutorial.

Now there are two options:
1 (confirmed working) Compile the model on the Pi Zero directly.
2 cross-compile for your target architecture

Good luck to whoever is trying something similar.

Now all that’s left to do is write the sensor input data pipeline in C++.

I got this working on my raspberry pi zero.
Did you see the post on the forum?

Perhaps it will work for you.

Install on Raspberry Pi Zero - Solved

@Gerry

I have read your post and it was a great help with the CLI installation on my Pi. I can however still not get the edge-impulse-linux-runner CLI tool to work:

pi@raspberrypi:~/buzzinga/edge/model_deploy/buzzinga-project-1-v5$ edge-impulse-linux-runner
Edge Impulse Linux runner v1.3.1
    Project:     buzzinga-project-1 (ID: 82131)

[RUN] Failed to run impulse Error: Unsupported architecture "armv6l", only armv7l or aarch64 supported for now
    at RunnerDownloader.getDownloadType (/usr/lib/node_modules/edge-impulse-linux/build/cli/linux/runner-downloader.js:35:27)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RunnerDownloader.getLastDeploymentVersion (/usr/lib/node_modules/edge-impulse-linux/build/cli/linux/runner-downloader.js:62:28)
    at async /usr/lib/node_modules/edge-impulse-linux/build/cli/linux/runner.js:126:31

How did you deploy your model to the Pi ?

Ahh, I didn’t get that far. :grinning:

Yeah, reading the doco (for once), its not going to work unless you compile your own binary file as
@buzzinga has described.


Edge Impulse for Linux models are delivered in .eim format. This is an executable that contains your signal processing and ML code, compiled with optimizations for your processor or GPU

Hi @buzzinga,

Which model / specs of Raspberry Pi do you have?

Hi @jenny . Thanks for getting on this so quickly:

processor : 0
model name : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 997.08
Features : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7

Hardware : BCM2835
Revision : 9000c1
Serial : 000000008f5aad25
Model : Raspberry Pi Zero W Rev 1.1

Got it working. :partying_face: :partying_face:

Turns out it was a matter of memory usage and me having accidently pre-compiled parts of the library on my local machine, which of course causes incompatible binaries.

make -j 2

Worked fine for me.

1 Like

Can you put the details here, how you make it worked on RPi zero please

@vijayrraut

Follow the instructions here: https://docs.edgeimpulse.com/docs/deploy-your-model-as-a-c-library#explanation-of-the-makefile

Use the standard makefile from the tutorial and compile the C++ library on the RPi zero directly.

Thanks @buzzinga, fixed this by updating the npm version to @6.14.15, and then run
npm config set user root && sudo npm install edge-impulse-linux -g --unsafe-perm command.

2 Likes

I am unable to compile a C++ library on the Raspberry Pi Zero because the execution stops at some random point and the whole system is frozen.

How can I deploy my model to pi?

@Sushmita_36, what is the output you are getting?

I am not getting an error but my screen is frozen while compiling.

This is usually because there is not enough memory available on the RPI, you can specific the numbers of cores to be used when compiling. For example, make -j1 for one core, and -j2 for 2 cores.

I have tried make -j2 but my system is still frozen at some point. How can I compile my model?

A couple of solutions:

  • You can cross compile the model for the RPI 0 if you have a more powerful machine e.g, x86
    Or
  • You can monitor the RAM consumption in real time using htop command.
  • Try to free some RAM and do not use a graphical interface.
  • Try to compile with -j1 as well

I can cross compile the model for the Rpi 0.
Thanks for all solutions.

I have never done cross compilation. Can you please guide me on how to cross-compile a C++ library for the Raspberry Pi Zero?