Repository navigation
Expand file tree
/
Copy pathIrisExample.ino
More file actions
81 lines (67 loc) · 2.12 KB
/
Copy pathIrisExample.ino
File metadata and controls
81 lines (67 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Run a TensorFlow model to predict the IRIS dataset
* For a complete guide, visit
* https://eloquentarduino.com/tensorflow-lite-esp32
*/
// replace with your own model
// include BEFORE <eloquent_tinyml.h>!
#include "irisModel.h"
// include the runtime specific for your board
// either tflm_esp32 or tflm_cortexm
#include <tflm_esp32.h>
// now you can include the eloquent tinyml wrapper
#include <eloquent_tinyml.h>
// this is trial-and-error process
// when developing a new model, start with a high value
// (e.g. 10000), then decrease until the model stops
// working as expected
#define ARENA_SIZE 2000
Eloquent::TF::Sequential<TF_NUM_OPS, ARENA_SIZE> tf;
/**
*
*/
void setup() {
Serial.begin(115200);
delay(3000);
Serial.println("__TENSORFLOW IRIS__");
// configure input/output
// (not mandatory if you generated the .h model
// using the everywhereml Python package)
tf.setNumInputs(4);
tf.setNumOutputs(3);
// add required ops
// (not mandatory if you generated the .h model
// using the everywhereml Python package)
tf.resolver.AddFullyConnected();
tf.resolver.AddSoftmax();
while (!tf.begin(irisModel).isOk())
Serial.println(tf.exception.toString());
}
void loop() {
// classify class 0
if (!tf.predict(x0).isOk()) {
Serial.println(tf.exception.toString());
return;
}
Serial.print("expcted class 0, predicted class ");
Serial.println(tf.classification);
// classify class 1
if (!tf.predict(x1).isOk()) {
Serial.println(tf.exception.toString());
return;
}
Serial.print("expcted class 1, predicted class ");
Serial.println(tf.classification);
// classify class 2
if (!tf.predict(x2).isOk()) {
Serial.println(tf.exception.toString());
return;
}
Serial.print("expcted class 2, predicted class ");
Serial.println(tf.classification);
// how long does it take to run a single prediction?
Serial.print("It takes ");
Serial.print(tf.benchmark.microseconds());
Serial.println("us for a single prediction");
delay(1000);
}