Skip to content

Commit 8027eef

Browse files
Move out mlrunner files into a different repo added as a submodule.
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.
1 parent 3d9bfaf commit 8027eef

File tree

14 files changed

+121
-2309
lines changed

14 files changed

+121
-2309
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "micropython-microbit-v2"]
22
path = micropython-microbit-v2
33
url = https://github.com/microbit-foundation/micropython-microbit-v2.git
4+
[submodule "ml-module/pxt-ml-runner-poc"]
5+
path = ml-module/pxt-ml-runner-poc
6+
url = https://github.com/microbit-foundation/pxt-ml-runner-poc.git

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ML4F MicroPython module
1+
# ML4F MicroPython module proof of concept
22

33
An experiment to integrate ML4F into MicroPython.
44

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

88
Clone this repository and initialise the git submodules (recursive submodule
99
init will unnecessarily initialise all submodules from all MicroPython ports):
10-
```
10+
11+
```bash
12+
git clone https://github.com/microbit-foundation/micropython-ml4f-poc.git
13+
cd micropython-ml4f-poc
1114
git submodule update --init
1215
git -C micropython-microbit-v2 submodule update --init
16+
git -C ml-module/pxt-ml-runner-poc submodule update --init
1317
```
1418

1519
Changes to the micro:bit MicroPython port are required for this experiment:
16-
```
20+
21+
```bash
1722
git -C micropython-microbit-v2 apply ../micropython-microbit-v2.patch
1823
```
1924

2025
Build MicroPython's mpy-cross:
21-
```
26+
27+
```bash
2228
make -C micropython-microbit-v2/lib/micropython/mpy-cross
2329
```
2430

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

27-
```
33+
```bash
2834
make -C micropython-microbit-v2/src USER_C_MODULES=../../..
2935
```
3036

3137
Copy the hex file to the micro:bit:
32-
```
38+
```bash
3339
cp micropython-microbit-v2/src/build/MICROBIT.hex /Volumes/MICROBIT
3440
```
3541

3642
Transfer the example Python code into the board with
3743
[microFS](https://github.com/ntoll/microfs):
38-
```
44+
45+
```bash
3946
ufs put ml-module/model-example/main.py
4047
```

ml-module/main.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
import ml
55

6+
print("Input size: {}".format(ml.get_input_length()))
7+
print("Model labels: {}".format(ml.get_labels()))
8+
69
TOTAL_SAMPLES = ml.get_input_length()
710
acc_x_y_z = [0] * TOTAL_SAMPLES
811

9-
print("Model labels: {}".format(ml.get_labels()))
10-
print("Input size: {}".format(TOTAL_SAMPLES))
11-
1212
i = 0
1313
while True:
1414
acc_x_y_z[i + 0] = accelerometer.get_x()
@@ -26,12 +26,4 @@
2626
else:
2727
print("t[{}] {}".format(time.ticks_ms() - t, result))
2828
i = 0
29-
if button_a.is_pressed():
30-
print("Use build-in model")
31-
ml.internal_model(True)
32-
sleep(500)
33-
if button_b.is_pressed():
34-
print("Use flash model")
35-
ml.internal_model(False)
36-
sleep(500)
3729
sleep(20)

ml-module/micropython.mk

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
CPPEXAMPLE_MOD_DIR := $(USERMOD_DIR)
22

33
SRC_USERMOD += \
4-
$(CPPEXAMPLE_MOD_DIR)/ml-runner/model-example/model_example.c \
5-
$(CPPEXAMPLE_MOD_DIR)/ml-runner/ml4f/ml4f.c \
4+
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/ml4f.c \
5+
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/mlrunner.c \
6+
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/mldataprocessor.c \
7+
$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner/example_dataprocessor.c \
8+
$(CPPEXAMPLE_MOD_DIR)/src/mlinterface.c \
69
$(CPPEXAMPLE_MOD_DIR)/src/mlmodule.c
710

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

10-
CFLAGS_USERMOD += -I$(CPPEXAMPLE_MOD_DIR)/ml-runner
13+
COMMON_FLAGS = \
14+
-I$(CPPEXAMPLE_MOD_DIR)/src \
15+
-I$(CPPEXAMPLE_MOD_DIR)/pxt-ml-runner-poc/mlrunner \
16+
-DDEVICE_MLRUNNER_USE_EXAMPLE_MODEL=2 \
17+
-DML_DEBUG_PRINT=1
1118

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

ml-module/ml-runner/ml4f/ml4f.c

Lines changed: 0 additions & 139 deletions
This file was deleted.

ml-module/ml-runner/ml4f/ml4f.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)