Skip to content

Commit

Permalink
Move out mlrunner files into a different repo added as a submodule.
Browse files Browse the repository at this point in the history
This is to be able to share the common code with MakeCode.

As PXT extensions cannot use submodules the mlrunner lib code
lives in the pxt extension and that repository is included here
as a sumodule.
  • Loading branch information
microbit-carlos committed Jun 4, 2024
1 parent 3d9bfaf commit 8027eef
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 2,309 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "micropython-microbit-v2"]
path = micropython-microbit-v2
url = https://github.com/microbit-foundation/micropython-microbit-v2.git
[submodule "ml-module/pxt-ml-runner-poc"]
path = ml-module/pxt-ml-runner-poc
url = https://github.com/microbit-foundation/pxt-ml-runner-poc.git
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ML4F MicroPython module
# ML4F MicroPython module proof of concept

An experiment to integrate ML4F into MicroPython.

Expand All @@ -7,34 +7,41 @@ An experiment to integrate ML4F into MicroPython.

Clone this repository and initialise the git submodules (recursive submodule
init will unnecessarily initialise all submodules from all MicroPython ports):
```

```bash
git clone https://github.com/microbit-foundation/micropython-ml4f-poc.git
cd micropython-ml4f-poc
git submodule update --init
git -C micropython-microbit-v2 submodule update --init
git -C ml-module/pxt-ml-runner-poc submodule update --init
```

Changes to the micro:bit MicroPython port are required for this experiment:
```

```bash
git -C micropython-microbit-v2 apply ../micropython-microbit-v2.patch
```

Build MicroPython's mpy-cross:
```

```bash
make -C micropython-microbit-v2/lib/micropython/mpy-cross
```

And build MicroPython with the ML module (and example model) included:

```
```bash
make -C micropython-microbit-v2/src USER_C_MODULES=../../..
```

Copy the hex file to the micro:bit:
```
```bash
cp micropython-microbit-v2/src/build/MICROBIT.hex /Volumes/MICROBIT
```

Transfer the example Python code into the board with
[microFS](https://github.com/ntoll/microfs):
```

```bash
ufs put ml-module/model-example/main.py
```
14 changes: 3 additions & 11 deletions ml-module/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import ml

print("Input size: {}".format(ml.get_input_length()))
print("Model labels: {}".format(ml.get_labels()))

TOTAL_SAMPLES = ml.get_input_length()
acc_x_y_z = [0] * TOTAL_SAMPLES

print("Model labels: {}".format(ml.get_labels()))
print("Input size: {}".format(TOTAL_SAMPLES))

i = 0
while True:
acc_x_y_z[i + 0] = accelerometer.get_x()
Expand All @@ -26,12 +26,4 @@
else:
print("t[{}] {}".format(time.ticks_ms() - t, result))
i = 0
if button_a.is_pressed():
print("Use build-in model")
ml.internal_model(True)
sleep(500)
if button_b.is_pressed():
print("Use flash model")
ml.internal_model(False)
sleep(500)
sleep(20)
19 changes: 14 additions & 5 deletions ml-module/micropython.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
CPPEXAMPLE_MOD_DIR := $(USERMOD_DIR)

SRC_USERMOD += \
$(CPPEXAMPLE_MOD_DIR)/ml-runner/model-example/model_example.c \
$(CPPEXAMPLE_MOD_DIR)/ml-runner/ml4f/ml4f.c \
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/ml4f.c \
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/mlrunner.c \
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/mldataprocessor.c \
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/example_dataprocessor.c \
$(CPPEXAMPLE_MOD_DIR)/src/mlinterface.c \
$(CPPEXAMPLE_MOD_DIR)/src/mlmodule.c

SRC_USERMOD_CXX += $(CPPEXAMPLE_MOD_DIR)/ml-runner/mlrunner.cpp
# SRC_USERMOD_CXX += $(CPPEXAMPLE_MOD_DIR)/ml-runner/mlrunner.cpp

CFLAGS_USERMOD += -I$(CPPEXAMPLE_MOD_DIR)/ml-runner
COMMON_FLAGS = \
-I$(CPPEXAMPLE_MOD_DIR)/src \
-I$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner \
-DDEVICE_MLRUNNER_USE_EXAMPLE_MODEL=2 \
-DML_DEBUG_PRINT=1

CXXFLAGS_USERMOD += -I$(CPPEXAMPLE_MOD_DIR)/ml-runner -std=c++11
CFLAGS_USERMOD += $(COMMON_FLAGS)

CXXFLAGS_USERMOD += $(COMMON_FLAGS) -std=c++11
139 changes: 0 additions & 139 deletions ml-module/ml-runner/ml4f/ml4f.c

This file was deleted.

60 changes: 0 additions & 60 deletions ml-module/ml-runner/ml4f/ml4f.h

This file was deleted.

Loading

0 comments on commit 8027eef

Please sign in to comment.