TensorFlow Lite Micro Support for Artemis

I am working on getting the Micro Voice demo working on the Artemis RedBoard. I have been taking the steps used to get it working on the Edge and Edge 2, and just running it. There is a general walk through here: https://codelabs.developers.google.com/ … sorflow/#0

I am pretty sure I need to point to the BSP for the RedBoard instead. I have managed to at least get it to compile and have it spit out some info over Serial.

I am running this on OSX. You will have to use brew or MacPorts to get a newer version of make and then make sure the updated version is used as the default.

I am using the SparkFun fork of TensorFlow, which @liquid.soulder has been updating to work with the Edge 2 and the latest version of the Ambiq SDK.

Here are the steps I take:

git clone https://github.com/sparkfun/tensorflow.git
cd tensorflow
gmake -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=sparkfun_edge2 micro_speech_bin

Oddly, I have to run this twice because I get a sed error. it works fine the second time.

I then use this command to flash the compiled bin. In order to flash, I need to pull the boot loader pin high. Follow the directions here: viewtopic.php?f=168&t=50825#p207893

Basically, connect a jump wire to 3.3v. Touch the other end to the right side of the resistor that is above LED 13. With this connection made, hit the reset button. Continue to keep the connection and then run the following command:

python3 tensorflow/lite/experimental/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/boards_sfe/common/tools_sfe/ambiq/ambiq_bin2board.py --bin tensorflow/lite/experimental/micro/tools/make/gen/sparkfun_edge2_cortex-m4/bin/micro_speech.bin --load-address-blob 0x20000 --magic-num 0xCB -o main_nonsecure_ota --version 0x0 --load-address-wired 0xC000 -i 6 --options 0x1 -b 115200 -port /dev/cu.usbserial-1410 -r 2 -v

After doing all of that… all I get is the follow if I open up serial monitor:

FPU Enabled.

PDM DMA Threshold = 16

I am going to go in and try modifying the Makefile to point to the correct BSP for the RedBoard. I will keep this thread updated as I make progress. If anyone has figured this out, please contribute!

OK! I got MicroVoice working on a RedBoard!

It is still a little wonky… and there is some debug code in there that appears to be structural. There is some sort of timing or interrupt issue and if you remove the debug statements I added, it breaks. Those debug messages are in command_reciever.cc on lines 52, 56 & 60. I will try to hunt down the root cause, but wanted to pass this progress along because it is fun to play with.

My fork of the SparkFun branch is here: https://github.com/robotastic/tensorflo … 7eb0cfe9d7

This code should build the bin:

gmake -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=sparkfun_redboard_artemis micro_speech_bin

Use the flashing technique described above and the following command to flash:

python3 tensorflow/lite/experimental/micro/tools/make/downloads/AmbiqSuite-Rel2.2.0/boards_sfe/common/tools_sfe/ambiq/ambiq_bin2board.py --bin tensorflow/lite/experimental/micro/tools/make/gen/sparkfun_redboard_artemis_cortex-m4/bin/micro_speech.bin --load-address-blob 0x20000 --magic-num 0xCB -o main_nonsecure_ota --version 0x0 --load-address-wired 0xC000 -i 6 --options 0x1 -b 115200 -port /dev/cu.usbserial-1410 -r 2 -v

Now, open up Serial Monitor and say Yes or No. I have found making it a really long Noooooo seems to help with recognition.

That’s great! Keep us updated on your progress. I am also looking to get this functionality working in an upcoming project.

I updated my code against the latest version of Tensorflow and things are working a lot more reliably. I have tested against the Redboard Artemis and Edge 2. Folks have also reported it work with the ATP. This is for the Micro-Voice example.

I also figured out that I was having trouble flashing the board and having to use a jumper wire because I didn’t have a current version of the CH340 driver installed.

Checkout the sparkfun_artemis branch of this repo:

https://github.com/robotastic/tensorflo … un_artemis

I’ve adapted the Tensorflow_AIOT2019 SparkFun Edge micro speech sample for Arduino to the SparkFun Artemis ATP development board.

https://www.hackster.io/javagoza/artemi … ple-d95f08

https://github.com/javagoza/ArtemisATPT … /README.md

I would go and check out the Sparkfun TensorFlow repo on Github. They have added support for all of the Artemis boards and I think there is now arduino compatibility for the TF libraries!!

https://github.com/sparkfun/tensorflow

@robotastic - I never reached an acceptable conclusion, in my mind, about the issues we were having with the Artemis module based boards. I just wanted to check in with you about the status of [your branch. Have you continued to use the micro_speech example on the RedBoard Artemis and or the RedBoard Artemis ATP?

I’m hoping that soon I will have some bandwidth open up to allow me to put those issues to rest so that we can be confident that all the Apollo3 based boards we sell are TFLu compatible.

Also thanks again for your hard work on this at the end of last year!](GitHub - robotastic/tensorflow at sparkfun_artemis)

@liquid.soulder I didn’t keep running with it after I got it working… My branch of code is now way behind. I am now starting to work on TinyML for a new project though. I would be game to take another swing at it.

Now that Arduino is running on Artemis pretty reliably, would it be better to have TF Lite Micro compile for an Arduino target and then run the Arduino Library it generates? I am not sure if it would take a performance hit going the Arduino route. The benefit is that it would be a lot easier to pull in other sensors or hook it up to LoRa.

Good to hear back from you - in the time since you’ve been gone we got some PRs accepted into TFLu including both an update to the BSP repo that is used (so that more boards are available) and the inclusion of the Edge board in the Arduino library build.

I don’t know whether the Arduino library has actually been updated in the Arduino Library Manager though (but you can build it yourself from the latest TFLu repo) Here are Pete Warden’s instructions for building the Arduino library:

To generate the Arduino library, download the main repo at https://github.com/tensorflow/tensorflow and then run https://github.com/tensorflow/tensorflo … arduino.sh

Furthermore the Artemis based boards still aren’t included - I have been working on enabling them to run mbed os (releasing soon, stay tuned!) But with the addition of our new BSP repo into the default project it should be a lot easier.

The most worrying thing on my mind is of course the odd behavior that we were investigating last fall. (Hard faults etc…) If we can work past that then we should have a good foundation! I hope that I will be able to focus more on this as soon as we release mbed support. Keep me updated on anything interesting you find.

Cheers!