emlearn-micropython
emlearn-micropython copied to clipboard
Add emlearn as USER_C_MODULE
This is a POC to add emlearn as a frozen USER_C_MODULE in firmware.
I had to modify/comment some lines, but I got it working (just git diff with the original files to see it)
MicroPython v1.20.0-363-g6d9f9d9ea-dirty on 2023-07-30; darwin [GCC 4.2.1] version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import emlearn
>>> emlearn.
open __dict__ addnode addroot
factorial predict
>>>
and
$ micropython xor_usermod_run.py
nodes=7fb4dd606460 roots=7fb4dd6063a0 builder=7fb4dd606308
array('f', [0.0, 0.0]) 0
array('f', [1.0, 1.0]) 0
array('f', [0.0, 1.0]) 1
array('f', [1.0, 0.0]) 1
Not sure if you are interested but I hope this helps as a reference 👍🏼
Hi @Carglglz. Very cool! Fastest external merge request I have seen - I just made the repository public some hours ago :D
I have actually never tried to make a user module, so this should be helpful. I don't even think I know how to include it right now, but I have seen there is documentation for that. I've been working on the native module case, as I really like the idea of getting started without needing rebuild/reflash. But it is ideal to have both options, I think.
@jonnor
I don't even think I know how to include it right now, but I have seen there is documentation for that.
Don't worry I was curious if this could work and it does, then I've just made the draft so you can have a reference in case you want to test/implement it see https://docs.micropython.org/en/latest/develop/cmodules.html
I've been working on the native module case, as I really like the idea of getting started without needing rebuild/reflash. But it is ideal to have both options, I think.
Yes the native module case is probably the way to go for fast iteration, but when you're happy with the result then adding it as a frozen module may save some RAM/ improve performance (although I have not tested it in this case)
I created an issue to track this enhancement request. https://github.com/emlearn/emlearn-micropython/issues/18 Closing this MR since it was primarily a proof of concept, and is now incompatible since there has been many changes over the last year.