Object Detection on M4 core

I will test all 4 main edgeimpulse methods on the Portenta M4 core.

First FOMO:

@louis @ElectricDragon I am trying 64x64 MobileNetV2 0.01 FOMO and my first error is

C:\Arduino-1.8.19\portable\packages\arduino\hardware\mbed_portenta\3.1.1\libraries\Camera\src\camera.cpp: In function 'void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef*)':

C:\Arduino-1.8.19\portable\packages\arduino\hardware\mbed_portenta\3.1.1\libraries\Camera\src\camera.cpp:120:27: error: 'DCMI_TIM' was not declared in this scope
     if (htim->Instance == DCMI_TIM) {

Sound PDM seems to work on both the Portenta M4 and M7 cores. Of course on the M4 core serial print does not work on the M4 and cool tricks using RPC seem to give the red flash of death, but just activating the LED’s red, green, blue: LEDR, LEDG, LEDB seems to work.

Acceleration might work on the M4 core, it compiled and while I was messing with LED’s I lost the serial port. The Portenta just flashes red once on plugin and I can’t seem to connect to it. Possibly bricked another one. :sob:

Next trying classification.

Same issue on the Portenta M4 for Classification as for FOMO

C:\Arduino-1.8.19\portable\packages\arduino\hardware\mbed_portenta\3.1.1\libraries\Camera\src\camera.cpp: In function 'void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef*)':
C:\Arduino-1.8.19\portable\packages\arduino\hardware\mbed_portenta\3.1.1\libraries\Camera\src\camera.cpp:120:27: error: 'DCMI_TIM' was not declared in this scope
     if (htim->Instance == DCMI_TIM) {

@rjames any suggestions? I am going to try a few camera sketches from here on the M4 core.

I filed an issue on the Arduino core MBED site

I successfully got the Arduino example “portenta_h7_microphone_continuous” running on the M4. Debug statements are sent to the M7 via RPC with the M7 doing the Serial.println().

Yes…@rocksetta, I get the same error when I try to upload to the M4 core.

Nice @MMarcial my little RPC trick did not work on the M4 core with sound, but maybe I di something else wrong, might have another look at it.

#include "RPC.h"  // comes with the mbed board installation

#define Serial RPC  // So the M4 regular serial prints go to RPC

@ElectricDragon I havn’t tested an ML model but using my OLED I got the camera working on the PortentaH7 M4 core

My camera.cpp code is here

I cut out a function but not sure if that is a good idea, but it works. Waiting for a reply from Arduino. I will try testing it tonight on a FOMO model.

Sad to say my first FOMO attempt compiled but I have no proof if it worked. I will try again tomorrow.

Why are you thinking we should do a smaller model on the M4 core? I thought the PortentaH7 M4 core actually had more space than the M7?

Having said that my 96x96 model is not working so I am now trying your 64x64 model idea.

@louis I got your model size working! I just have to improve it a bit, but it looks like M4 is very finicky but can do a FOMO model.

link to post of FOMO working on M4 here

1 Like

I like that trick. It allows keeping one code base depending on the target application.

1 Like

@Rocksetta so would a FOMO model work if the size is 64x64? Or are there a few more steps that need to be taken?

Yeh, took a long time to get to that point, see these deprecated examples (all done 2 years ago!). I am testing if I can get RPC on the M4 working with Edgeimpulse. I assume the problem is the ie_printf() command but on closer inspection of an exported arduino library (…src\edge-impulse-sdk\porting\arduino\ei_classifier_porting.cpp) it does seem to eventually do a Serial.print()

Presently not getting anything from ei_printf() through RPC , perhaps one of the Pro’s could voice an opinion.

I would just get 64x64 FOMO working on M4 and then increase the size. I use an OLED to view my output (Really worth $12.99 USD 1.5inch OLED display Module, 128x128 pixels, 16 gray scale, SPI/I2C interface) so that is probably trashing a fair bit of my memory allocation. I should try a model with just the LED output (as serial through RPC is a pain) and see how big it can go. After 96x96 things on M7 get tricky. I would like 160x160 but that hits a memory limit however I have not tried @louis suggestion of the smaller mobileNet.

I blindly replaced all ei_printf() with equivalent RPC.print(). Also the M4 code would not run if I had RPC.print() in the Arduino setup().

@MMarcial

Why is that so?

@MMarcial @ElectricDragon

Not sure either way, but I do have a 64x64 model working from the M4 core with RPC here, but as I try to print more info with Serial.print I get the dreaded TFlite Arena error issue, which I don’t want to use the local.boards.txt trick to solve.

Predictions 
x:32, y:24
Starting inferencing in 0 microseconds...
Taking photo...

Predictions 
x:32, y:24
Starting inferencing in 0 microseconds...
Taking photo...

Easiest way to do the example is to load my “Portenta Pro Community Solutions” library in your Arduino IDE (search for community) and load one of the FOMO models to get the include file setup (dot514 folder) and then replace the main code with the above code.

the 64x64 model I am using is in the same folder but is really badly trained on a simple red cup so it is not the best model to use. I will use a better 3 object model when I test more.

1 Like

I was mistaken. I retested RPC.println() in setup() and it works, The M4 loop() continues to execute.

1 Like

So I am getting 80x80 FOMO working on M4 with RPC and LED’s but I solved an issue. Printing confidence values as a float is a pain. Easier to x100 print the integer with “0.” in front of it.

Code is here again

Is the intent of "String( int(bb.value*100) )" to print a float to 2 decimal places versus "String(bb.value)" that would print to 6 decimal places?

I think what I was trying to do there is that printing floats can be a pain, so I just changed the float into a integer percent value.

example 0.234534 becomes 23 and prints much easier than printing a float.

By the way Arduino MBED boards version 3.2.0 was released quietly about 6 days ago, and I checked and my changes to make the M4 core do vision is in the camera.cpp code. Hopefully it works by default now.

#if defined (ARDUINO_PORTENTA_H7_M7) || defined (ARDUINO_PORTENTA_H7_M4)

I haven’t re-tested it, but hopefully small M4 vision models now work.