Skip to content

Commit 1cfd8b6

Browse files
Merge pull request #32 from smuellener/feature/supportMultipleNetworks
Allow using multiple networks by supporting multiple instances of TfLite
2 parents fc99c6b + 013bea6 commit 1cfd8b6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/EloquentTinyML.h

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,21 @@ namespace Eloquent {
4949
failed(false) {
5050
}
5151

52+
~TfLite() {
53+
delete reporter;
54+
delete interpreter;
55+
}
56+
5257
/**
5358
* Inizialize NN
5459
*
5560
* @param modelData
5661
* @return
5762
*/
5863
bool begin(const unsigned char *modelData) {
59-
static tflite::MicroErrorReporter microReporter;
60-
static tflite::ops::micro::AllOpsResolver resolver;
64+
tflite::ops::micro::AllOpsResolver resolver;
65+
reporter = new tflite::MicroErrorReporter();
6166

62-
reporter = &microReporter;
6367
model = tflite::GetModel(modelData);
6468

6569
// assert model version and runtime version match
@@ -75,21 +79,19 @@ namespace Eloquent {
7579
return false;
7680
}
7781

78-
static tflite::MicroInterpreter interpreter(model, resolver, tensorArena, tensorArenaSize, reporter);
82+
interpreter = new tflite::MicroInterpreter(model, resolver, tensorArena, tensorArenaSize, reporter);
7983

80-
if (interpreter.AllocateTensors() != kTfLiteOk) {
84+
if (interpreter->AllocateTensors() != kTfLiteOk) {
8185
failed = true;
8286
error = CANNOT_ALLOCATE_TENSORS;
8387

8488
return false;
8589
}
8690

87-
input = interpreter.input(0);
88-
output = interpreter.output(0);
91+
input = interpreter->input(0);
92+
output = interpreter->output(0);
8993
error = OK;
9094

91-
this->interpreter = &interpreter;
92-
9395
return true;
9496
}
9597

@@ -192,6 +194,14 @@ namespace Eloquent {
192194
return classIdx;
193195
}
194196

197+
/**
198+
* Get error
199+
* @return
200+
*/
201+
TfLiteError getError() {
202+
return error;
203+
}
204+
195205
/**
196206
* Get error message
197207
* @return

0 commit comments

Comments
 (0)