Skip to content

Commit aa6dd92

Browse files
committed
fix sine example
1 parent 089460b commit aa6dd92

File tree

10 files changed

+19839
-416
lines changed

10 files changed

+19839
-416
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ git clone https://github.com/eloquentarduino/EloquentTinyML.git
2828
Eloquent::TinyML::TinyML<
2929
NUMBER_OF_INPUTS,
3030
NUMBER_OF_OUTPUTS,
31-
TENSOR_ARENA_SIZE> ml(sine_model_quantized_tflite);
31+
TENSOR_ARENA_SIZE> ml;
3232

3333

3434
void setup() {
3535
Serial.begin(115200);
36+
ml.begin(sine_model_quantized_tflite);
3637
}
3738

3839
void loop() {

examples/ColorClassificationTrainingExample/ColorClassificationTrainingExample.ino

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

examples/ColorClassificationTrainingExample/RGB.h

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

examples/SineExample/SineExample.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
// in future projects you may need to tweek this value: it's a trial and error process
88
#define TENSOR_ARENA_SIZE 2*1024
99

10-
Eloquent::TinyML::TfLite<NUMBER_OF_INPUTS, NUMBER_OF_OUTPUTS, TENSOR_ARENA_SIZE> ml(sine_model);
10+
Eloquent::TinyML::TfLite<NUMBER_OF_INPUTS, NUMBER_OF_OUTPUTS, TENSOR_ARENA_SIZE> ml;
1111

1212

1313
void setup() {
1414
Serial.begin(115200);
15+
ml.begin(sine_model);
1516
}
1617

1718
void loop() {

examples/SineExample/sine_model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
unsigned char sine_model[] = {
3+
const unsigned char sine_model[] = {
44
0x18, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x00, 0x00, 0x0e, 0x00,
55
0x18, 0x00, 0x04, 0x00, 0x08, 0x00, 0x0c, 0x00, 0x10, 0x00, 0x14, 0x00,
66
0x0e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, 0x0a, 0x00, 0x00,

src/EloquentPersonDetector.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#pragma once
2+
3+
#include "EloquentTinyML.h"
4+
#include "persondetection/model.h"
5+
6+
// Keeping these as constant expressions allow us to allocate fixed-sized arrays
7+
// on the stack for our working memory.
8+
9+
// All of these values are derived from the values used during model training,
10+
// if you change your model you'll need to update these constants.
11+
const int kNumCols = 96;
12+
const int kNumRows = 96;
13+
const int kNumChannels = 1;
14+
const int kMaxImageSize = kNumCols * kNumRows * kNumChannels;
15+
const int kCategoryCount = 3;
16+
const int kPersonIndex = 1;
17+
const int kNotAPersonIndex = 2;
18+
const char* kCategoryLabels[kCategoryCount] = {
19+
"unused",
20+
"person",
21+
"notperson",
22+
};
23+
24+
25+
namespace Eloquent {
26+
namespace TinyML {
27+
28+
/**
29+
*
30+
* @tparam tensorArenaSize
31+
*/
32+
template<size_t tensorArenaSize>
33+
class PersonDetector {
34+
public:
35+
PersonDetector() {
36+
37+
}
38+
39+
/**
40+
*
41+
* @return
42+
*/
43+
bool begin() {
44+
return tf.begin(g_person_detect_model_data);
45+
}
46+
47+
/**
48+
*
49+
* @return
50+
*/
51+
bool initialized() {
52+
return tf.initialized();
53+
}
54+
55+
void detect(uint8_t *grayscaleImage) {
56+
tf.predict(grayscaleImage, scores);
57+
}
58+
59+
/**
60+
*
61+
* @return
62+
*/
63+
uint8_t getPersonScore() {
64+
return scores[1];
65+
}
66+
67+
/**
68+
*
69+
* @return
70+
*/
71+
uint8_t getNonPersonScore() {
72+
return scores[2];
73+
}
74+
75+
/**
76+
*
77+
* @return
78+
*/
79+
bool isPerson() {
80+
return getPersonScore() > getNonPersonScore();
81+
}
82+
83+
protected:
84+
uint8_t scores[3];
85+
TfLite<kNumRows * kNumCols, 3, tensorArenaSize> tf;
86+
};
87+
}
88+
}

0 commit comments

Comments
 (0)