File tree Expand file tree Collapse file tree 14 files changed +121
-2309
lines changed Expand file tree Collapse file tree 14 files changed +121
-2309
lines changed Original file line number Diff line number Diff line change 1
1
[submodule "micropython-microbit-v2 "]
2
2
path = micropython-microbit-v2
3
3
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
Original file line number Diff line number Diff line change 1
- # ML4F MicroPython module
1
+ # ML4F MicroPython module proof of concept
2
2
3
3
An experiment to integrate ML4F into MicroPython.
4
4
@@ -7,34 +7,41 @@ An experiment to integrate ML4F into MicroPython.
7
7
8
8
Clone this repository and initialise the git submodules (recursive submodule
9
9
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
11
14
git submodule update --init
12
15
git -C micropython-microbit-v2 submodule update --init
16
+ git -C ml-module/pxt-ml-runner-poc submodule update --init
13
17
```
14
18
15
19
Changes to the micro: bit MicroPython port are required for this experiment:
16
- ```
20
+
21
+ ``` bash
17
22
git -C micropython-microbit-v2 apply ../micropython-microbit-v2.patch
18
23
```
19
24
20
25
Build MicroPython's mpy-cross:
21
- ```
26
+
27
+ ``` bash
22
28
make -C micropython-microbit-v2/lib/micropython/mpy-cross
23
29
```
24
30
25
31
And build MicroPython with the ML module (and example model) included:
26
32
27
- ```
33
+ ``` bash
28
34
make -C micropython-microbit-v2/src USER_C_MODULES=../../..
29
35
```
30
36
31
37
Copy the hex file to the micro:bit:
32
- ```
38
+ ``` bash
33
39
cp micropython-microbit-v2/src/build/MICROBIT.hex /Volumes/MICROBIT
34
40
```
35
41
36
42
Transfer the example Python code into the board with
37
43
[ microFS] ( https://github.com/ntoll/microfs ) :
38
- ```
44
+
45
+ ``` bash
39
46
ufs put ml-module/model-example/main.py
40
47
```
Original file line number Diff line number Diff line change 3
3
4
4
import ml
5
5
6
+ print ("Input size: {}" .format (ml .get_input_length ()))
7
+ print ("Model labels: {}" .format (ml .get_labels ()))
8
+
6
9
TOTAL_SAMPLES = ml .get_input_length ()
7
10
acc_x_y_z = [0 ] * TOTAL_SAMPLES
8
11
9
- print ("Model labels: {}" .format (ml .get_labels ()))
10
- print ("Input size: {}" .format (TOTAL_SAMPLES ))
11
-
12
12
i = 0
13
13
while True :
14
14
acc_x_y_z [i + 0 ] = accelerometer .get_x ()
26
26
else :
27
27
print ("t[{}] {}" .format (time .ticks_ms () - t , result ))
28
28
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 )
37
29
sleep (20 )
Original file line number Diff line number Diff line change 1
1
CPPEXAMPLE_MOD_DIR := $(USERMOD_DIR )
2
2
3
3
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 \
6
9
$(CPPEXAMPLE_MOD_DIR ) /src/mlmodule.c
7
10
8
- SRC_USERMOD_CXX += $(CPPEXAMPLE_MOD_DIR ) /ml-runner/mlrunner.cpp
11
+ # SRC_USERMOD_CXX += $(CPPEXAMPLE_MOD_DIR)/ml-runner/mlrunner.cpp
9
12
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
11
18
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
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments