Skip to content

Commit a7946cd

Browse files
authored
Merge pull request #17 from emlearn/fix-module-names
Make all modules have emlearn_xxx names
2 parents a2118bf + c823bbc commit a7946cd

File tree

42 files changed

+128
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+128
-165
lines changed

Makefile

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,49 @@ MPY_DIR_ABS = $(abspath $(MPY_DIR))
1010

1111
MODULES_PATH = ./dist/$(ARCH)_$(MPY_ABI_VERSION)
1212

13-
$(MODULES_PATH)/emltrees.mpy:
14-
make -C src/emltrees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
13+
$(MODULES_PATH)/emlearn_trees.mpy:
14+
make -C src/emlearn_trees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
1515

16-
$(MODULES_PATH)/emlneighbors.mpy:
17-
make -C src/emlneighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
16+
$(MODULES_PATH)/emlearn_neighbors.mpy:
17+
make -C src/emlearn_neighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
1818

19-
$(MODULES_PATH)/emliir.mpy:
20-
make -C src/emliir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
19+
$(MODULES_PATH)/emlearn_iir.mpy:
20+
make -C src/emlearn_iir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
2121

22-
$(MODULES_PATH)/emlfft.mpy:
23-
make -C src/emlfft/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
22+
$(MODULES_PATH)/emlearn_fft.mpy:
23+
make -C src/emlearn_fft/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
2424

25-
$(MODULES_PATH)/tinymaix_cnn.mpy:
25+
$(MODULES_PATH)/emlearn_cnn.mpy:
2626
make -C src/tinymaix_cnn/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
2727

28-
$(MODULES_PATH)/emlkmeans.mpy:
29-
make -C src/emlkmeans/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
28+
$(MODULES_PATH)/emlearn_kmeans.mpy:
29+
make -C src/emlearn_kmeans/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
3030

31-
$(MODULES_PATH)/eml_iir_q15.mpy:
32-
make -C src/eml_iir_q15/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
31+
$(MODULES_PATH)/emlearn_iir_q15.mpy:
32+
make -C src/emlearn_iir_q15/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
3333

3434
$(MODULES_PATH)/emlearn_arrayutils.mpy:
3535
make -C src/emlearn_arrayutils/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean dist
3636

37-
emltrees.results: $(MODULES_PATH)/emltrees.mpy
37+
emlearn_trees.results: $(MODULES_PATH)/emlearn_trees.mpy
3838
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_trees.py
3939

40-
emlneighbors.results: $(MODULES_PATH)/emlneighbors.mpy
40+
emlearn_neighbors.results: $(MODULES_PATH)/emlearn_neighbors.mpy
4141
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_neighbors.py
4242

43-
emliir.results: $(MODULES_PATH)/emliir.mpy
43+
emlearn_iir.results: $(MODULES_PATH)/emlearn_iir.mpy
4444
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_iir.py
4545

46-
emlfft.results: $(MODULES_PATH)/emlfft.mpy
46+
emlearn_fft.results: $(MODULES_PATH)/emlearn_fft.mpy
4747
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_fft.py
4848

49-
tinymaix_cnn.results: $(MODULES_PATH)/tinymaix_cnn.mpy
49+
emlearn_cnn.results: $(MODULES_PATH)/emlearn_cnn.mpy
5050
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_cnn.py
5151

52-
emlkmeans.results: $(MODULES_PATH)/emlkmeans.mpy
52+
emlearn_kmeans.results: $(MODULES_PATH)/emlearn_kmeans.mpy
5353
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_kmeans.py
5454

55-
eml_iir_q15.results: $(MODULES_PATH)/eml_iir_q15.mpy
55+
emlearn_iir_q15.results: $(MODULES_PATH)/emlearn_iir_q15.mpy
5656
MICROPYPATH=$(MODULES_PATH) $(MICROPYTHON_BIN) tests/test_iir_q15.py
5757

5858
emlearn_arrayutils.results: $(MODULES_PATH)/emlearn_arrayutils.mpy
@@ -61,9 +61,9 @@ emlearn_arrayutils.results: $(MODULES_PATH)/emlearn_arrayutils.mpy
6161
.PHONY: clean
6262

6363
clean:
64-
make -C src/emltrees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
65-
make -C src/emlneighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
66-
make -C src/emliir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
64+
make -C src/emlearn_trees/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
65+
make -C src/emlearn_neighbors/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
66+
make -C src/emlearn_iir/ ARCH=$(ARCH) MPY_DIR=$(MPY_DIR_ABS) V=1 clean
6767
rm -rf ./dist
6868

6969
RELEASE_NAME = emlearn-micropython-$(VERSION)
@@ -74,8 +74,8 @@ release:
7474
zip -r $(RELEASE_NAME).zip $(RELEASE_NAME)
7575
#cp $(RELEASE_NAME).zip emlearn-micropython-latest.zip
7676

77-
check: emltrees.results emlneighbors.results emliir.results eml_iir_q15.results emlfft.results emlkmeans.results emlearn_arrayutils.results tinymaix_cnn.results
77+
check: emlearn_trees.results emlearn_neighbors.results emlearn_iir.results emlearn_iir_q15.results emlearn_fft.results emlearn_kmeans.results emlearn_arrayutils.results emlearn_cnn.results
7878

79-
dist: $(MODULES_PATH)/emltrees.mpy $(MODULES_PATH)/emlneighbors.mpy $(MODULES_PATH)/emliir.mpy $(MODULES_PATH)/eml_iir_q15.mpy $(MODULES_PATH)/emlfft.mpy $(MODULES_PATH)/emlkmeans.mpy $(MODULES_PATH)/emlearn_arrayutils.mpy $(MODULES_PATH)/tinymaix_cnn.mpy
79+
dist: $(MODULES_PATH)/emlearn_trees.mpy $(MODULES_PATH)/emlearn_neighbors.mpy $(MODULES_PATH)/emlearn_iir.mpy $(MODULES_PATH)/emlearn_iir_q15.mpy $(MODULES_PATH)/emlearn_fft.mpy $(MODULES_PATH)/emlearn_kmeans.mpy $(MODULES_PATH)/emlearn_arrayutils.mpy $(MODULES_PATH)/emlearn_cnn.mpy
8080

8181

README.md

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,21 @@ Download the repository with examples etc
5757
git clone https://github.com/emlearn/emlearn-micropython
5858
```
5959

60-
## Installing from a release
60+
## Usage
61+
62+
Start with the instructions in [XOR example](./examples/xor_trees/).
63+
6164

6265
#### Find architecture and .mpy version
6366

67+
The correct .mpy files to use depend on the CPU architecture of your microcontroller,
68+
as well as the MicroPython version.
69+
70+
| MicroPython version | .mpy version |
71+
|---------------------| ------------- |
72+
| 1.23.x | 6.3 |
73+
74+
6475
Identify which CPU architecture your device uses.
6576
You need to specify `ARCH` to install the correct module version.
6677

@@ -79,43 +90,6 @@ Information is also available in the official documentation:
7990
[MicroPython: .mpy files](https://docs.micropython.org/en/latest/reference/mpyfiles.html#versioning-and-compatibility-of-mpy-files)
8091

8192

82-
#### Download release files
83-
84-
Download from [releases](https://github.com/emlearn/emlearn-micropython/releases).
85-
86-
#### Install on device
87-
88-
Copy the .mpy file for the correct `ARCH` to your device.
89-
```
90-
mpremote cp emltrees.mpy :emltrees.mpy
91-
mpremote cp emlneighbors.mpy :emlneighbors.mpy
92-
```
93-
94-
NOTE: If there is no ready-made build for your device/architecture,
95-
then you will need to build the .mpy module yourself.
96-
97-
## Usage
98-
99-
NOTE: Make sure to install the module first (see above)
100-
101-
Train a model with scikit-learn
102-
```
103-
pip install emlearn scikit-learn
104-
python examples/xor_trees/xor_train.py
105-
```
106-
107-
Copy model file to device
108-
109-
```
110-
mpremote cp xor_model.csv :xor_model.csv
111-
```
112-
113-
Run program that uses the model
114-
115-
```
116-
mpremote run examples/xor_run.py
117-
```
118-
11993
## Benchmarks
12094

12195
#### UCI handwriting digits
@@ -157,7 +131,7 @@ make dist ARCH=armv6m MPY_DIR=../micropython
157131

158132
Install it on device
159133
```
160-
mpremote cp dist/armv6m*/emltrees.mpy :emltrees.mpy
134+
mpremote cp dist/armv6m*/emlearn_trees.mpy :emlearn_trees.mpy
161135
```
162136

163137
#### Run tests

benchmarks/digits_trees/digits_run.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
from everywhere_digits import RandomForestClassifier
88
import m2c_digits
9-
import emltrees
9+
import emlearn_trees
1010

1111

1212
def emlearn_create():
13-
model = emltrees.new(10, 1000, 10)
13+
model = emlearn_trees.new(10, 1000, 10)
1414

1515
# Load a CSV file with the model
1616
with open('eml_digits.csv', 'r') as f:
17-
emltrees.load_model(model, f)
17+
emlearn_trees.load_model(model, f)
1818
return model
1919

2020
def argmax(l):

benchmarks/fft/fft_benchmark.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
except ImportError as e:
1717
print(e)
1818

19-
emlfft = None
19+
emlearn_fft = None
2020
try:
21-
import emlfft
21+
import emlearn_fft
2222
pass
2323
except ImportError as e:
2424
print(e)
@@ -65,13 +65,13 @@ def run_one(real, imag, n, repeat=10):
6565
d = ((time.ticks_diff(time.ticks_us(), start)) / repeat) / 1000.0 # ms
6666
print('ulab', n, d)
6767

68-
# FIXME: this causes MicroPython to crash inside emlfft on ESP32
68+
# FIXME: this causes MicroPython to crash inside emlearn_fft on ESP32
6969
#gc.collect()
7070

7171
# emlearn
7272
if emlearn:
73-
fft2 = emlfft.FFT(n)
74-
emlfft.fill(fft2, n)
73+
fft2 = emlearn_fft.FFT(n)
74+
emlearn_fft.fill(fft2, n)
7575
gc.collect()
7676

7777
start = time.ticks_us()

benchmarks/fft/fft_benchmark.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# NOTE: MicroPython must be flashed before-hand
2-
# and emlfft.mpy built
2+
# and emlearn_fft.mpy built
33

44
MPREMOTE='mpremote'
55

6-
${MPREMOTE} cp src/emlfft/emlfft.mpy :
6+
${MPREMOTE} cp src/emlearn_fft/emlearn_fft.mpy :
77
${MPREMOTE} cp benchmarks/fft/fft_python.py :
88

99
${MPREMOTE} run benchmarks/fft/fft_benchmark.py

benchmarks/iir/iir_benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
print(e)
1515
pass
1616

17-
emliir = None
17+
emlearn_iir = None
1818
try:
19-
import emliir
19+
import emlearn_iir
2020
except ImportError as e:
2121
print(e)
2222
pass
@@ -70,9 +70,9 @@ def main():
7070
print('ulab', t)
7171

7272
# emlearn
73-
if emliir:
73+
if emlearn_iir:
7474
start = time.ticks_us()
75-
iir = emliir.new(coeff)
75+
iir = emlearn_iir.new(coeff)
7676
for r in range(repeats):
7777
iir.run(a)
7878
t = (time.ticks_diff(time.ticks_us(), start) / repeats ) / 1000.0 # ms

benchmarks/iir/iir_run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def iir_process_file(inp, out, filters, chunksize):
2727
if len(reader.shape) != 1:
2828
raise ValueError("Input must be 1d")
2929
if reader.typecode == 'f':
30-
import emliir
31-
filter = emliir.new(coefficients)
30+
import emlearn_iir
31+
filter = emlearn_iir.new(coefficients)
3232
elif reader.typecode == 'h':
33-
import eml_iir_q15
34-
filter = eml_iir_q15.new(coefficients)
33+
import emlearn_iir_q15
34+
filter = emlearn_iir_q15.new(coefficients)
3535
else:
3636
raise ValueError("Input must either be float32/f or int16/h")
3737

doc/TODO.md

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# User journey
44

55
- Level 0a. Run a pretrained example/demo in the browser
6-
- Level 0b. Run a pretrained example/demo on a board
6+
- Level 0b. Run a pretrained example/demo on PC/host
7+
- Level 0c. Run a pretrained example/demo on a board
78
- Level 1. Train custom model on-device
89
- Level 2. Collect a dataset, do training on PC, deploy back to microcontroller
910
- Level 3. Bake the custom model into the firmware
@@ -20,33 +21,21 @@
2021

2122
sequence. On-device training demo
2223

23-
- Record piezo data with ADC. 100 Hz?
24-
Typical taps. Slower pushes. Handling noises.
25-
- Setup event detection for piezo.
26-
In its own module.
27-
Threshold on delta and level?
28-
- Create emliir module, use for piezo detection
24+
- Use accelerometer instead of piezo. On M5StickC, for example
25+
- Compute impulsive-ness feature. Magnitude, RMS, exponential smooth, then Delta * times level ?
26+
- Alternative: Use IIR for knock detection
2927
- Maybe blink during unlocked state
3028
- Add a blink to each event. For user feedback
3129
- Make demo video
30+
- Add some documentation / README
3231
- Make state diagram
3332
- Make timing diagram. Highlight distances/features
34-
- Add some documentation / README
35-
36-
Learnings.
37-
38-
- Putting piezo on small thin plate worked well.
39-
On table not working, no response.
40-
Hitting direct not so good either, rise of finger causes change. Double-trigger. Also tricky to hit in right place.
41-
- LEDs as protection diodes worked well. Both red and green can be used. Lights up on direct hits, if placed by piezo.
42-
- Analog RC filter is beneficial for piezo connections. Using 10k+100nF, has 160 Hz cutoff. Should maybe move it to 80Hz? Since only sampling at 100 Hz.
43-
- Only direct hits can reach trigger levels on 3.3V I/O. Need ADC for other cases. But am seing some 100mV when placed on small plate
4433

45-
Examples
34+
#### Examples
4635

4736
- Add a novelty detection example?
4837

49-
Benchmarks
38+
#### Benchmarks
5039

5140
- Add FLASH and RAM usage
5241
- Test gzip compression of .csv model for trees
@@ -56,3 +45,5 @@ Benchmarks
5645
In-browser demo
5746

5847
- Test MicroPython build for WASM/browser
48+
- Test getting audio input into MicroPython Webassembly
49+
- Test getting IMU data (ie on phone), in browser

doc/micropython-tinyml-status.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ FIR filters.
167167

168168
IIR filters.
169169
`scipy.signal.sosfilt` available in [ulab](https://github.com/v923z/micropython-ulab).
170-
`emliir` available in [emlearn-micropython](https://github.com/emlearn/emlearn-micropython).
170+
`emlearn_iir` available in [emlearn-micropython](https://github.com/emlearn/emlearn-micropython).
171171

172172
### Fast Fourier Transform (FFT)
173173
Key part of computing frequency spectrum, or time-frequency representations (spectrogram).
174174

175175
FFT.
176176
`numpy.fft.fft` available in [ulab](https://github.com/v923z/micropython-ulab).
177-
`emlfft` available in [emlearn-micropython](https://github.com/emlearn/emlearn-micropython).
177+
`emlearn_fft` available in [emlearn-micropython](https://github.com/emlearn/emlearn-micropython).
178178

179179
DCT.
180180
Not available?
@@ -195,7 +195,7 @@ But over 10x slower than emlearn-micropython.
195195

196196
### K-nearest-neighbours
197197

198-
`emlneighbors` available in [emlearn-micropython](https://github.com/emlearn/emlearn-micropython).
198+
`emlearn_neighbors` available in [emlearn-micropython](https://github.com/emlearn/emlearn-micropython).
199199

200200
### Convolutional Neural Network
201201

examples/color_quantize_kmeans/color_quantize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import gc
1111

12-
import emlkmeans
12+
import emlearn_kmeans
1313

1414
@micropython.native
1515
def quantize_image(img, quant, palette, rowstride):
@@ -55,7 +55,7 @@ def quantize_image_inner(img, quant, palette, rowstride : int, rows : int):
5555
#rgb = img[i:i+3]
5656

5757
# find closest value in palette
58-
palette_idx, distance = emlkmeans.euclidean_argmin(palette, rgb)
58+
palette_idx, distance = emlearn_kmeans.euclidean_argmin(palette, rgb)
5959
#palette_idx, distance = 0, 0
6060

6161
o = row_offset + col
@@ -103,7 +103,7 @@ def quantize_path(inp, outp, palette, n_samples=100):
103103

104104
# Learn a palette
105105
start = time.ticks_us()
106-
emlkmeans.cluster(samples, palette, features=3, max_iter=20)
106+
emlearn_kmeans.cluster(samples, palette, features=3, max_iter=20)
107107
dur = (time.ticks_diff(time.ticks_us(), start) / 1000.0)
108108
print('cluster duration (ms)', dur)
109109

0 commit comments

Comments
 (0)