Skip to content

Allow using multiple networks by supporting multiple instances of TfLite #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2021
Merged

Allow using multiple networks by supporting multiple instances of TfLite #32

merged 1 commit into from
Oct 26, 2021

Conversation

smuellener
Copy link

With the current implementation it is not possible to use EloquentTinyML with multiple different networks due to static properties within the class. This pull request allows using multiple instances and hence multiple networks with EloquentTinyML.

  • Removed static properties to allow for multiple instances
  • Added destructor
  • Added access to TfLiteError for evaluation and error handling

+ Removed static properties to allow for multiple instances
+ Added destructor
+ Added access to TfLiteError for evaluation and error handling
@eloquentarduino eloquentarduino merged commit 1cfd8b6 into eloquentarduino:master Oct 26, 2021
@eloquentarduino
Copy link
Owner

Thank you for your contribution. I'll bump the library version for the Arduino Library Manager.
If I may ask, did you found yourself needing to run multiple networks at once?

@smuellener
Copy link
Author

Yes, in approximately the following way:

// Network 1
auto net_1 = new Eloquent::TinyML::TfLite<NUMBER_OF_INPUTS, NUMBER_OF_OUTPUTS, TENSOR_ARENA_SIZE>();
if (!net_1->begin(net_1_tflite))
{
    Serial.print("Cannot inialize model for network 1: ");
    Serial.println(net_1->errorMessage());
    return;
}
float out_1 = net_1->predict(input_1);
if (net_1->getError() != OK) Serial.println(net_1->errorMessage());
delete net_1;

// Network 2
auto net_2 = new Eloquent::TinyML::TfLite<NUMBER_OF_INPUTS, NUMBER_OF_OUTPUTS, TENSOR_ARENA_SIZE>();
if (!net_2->begin(net_2_tflite))
{
    Serial.print("Cannot inialize model for network 2: ");
    Serial.println(net_2->errorMessage());
    return;
}
float out_2 = net_2->predict(input_2);
if (net_2->getError() != OK) Serial.println(net_2->errorMessage());
delete net_2;

@smuellener smuellener deleted the feature/supportMultipleNetworks branch October 26, 2021 06:54
@whubaichuan
Copy link

@smuellener @eloquentarduino Thanks for your contribution.

I have tested the code in the original EloquentTinyMl:

tf.begin(model1);

# some test code about model1

tf.begin(model2);
# some test code about model2

It works. And maybe it's another method to run multiple networks in one project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants