Skip to content
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

Convertion possiblity #3

Open
ChabaneAmaury opened this issue Nov 26, 2021 · 2 comments
Open

Convertion possiblity #3

ChabaneAmaury opened this issue Nov 26, 2021 · 2 comments

Comments

@ChabaneAmaury
Copy link

Hello,

Would it be possible to add a convertion script, which would take an already trained and saved "regular" model to convert it to the edge's version?

Best,

@FouadSakr
Copy link
Contributor

Hello,

This feature is not supported but your contribution is welcome!

A script for this feature can look as follows (Assuming you saved your model and preprocessing params using pickle):
1- Read your saved model (using pickle),
2- Extract model parameters (e.g., in the case of SVM: support vectors, bias, etc.),
3- Pass these params to the save_params function (e.g., in SVM_OM.py),
4- Read the preprocessing parameters (e.g., PCA, Normalization, etc.) using the pickle framework also.
5- Extract preprocessing parameters (e.g, MinMax Scaler, PCA_components, etc.)
6- Pass preprocessing params to Preprocessing_OM.py.
7- Finally, the output source and header files containing model params and preprocessing params will be saved and ready to be used on the microcontrollers using the Micro-LM module.

Best,

@ChabaneAmaury
Copy link
Author

Hello,

The complicated part is that I meant something like convert a Tensorflow model to this KerasClassifier (for example). Unfortunately, there seems to be some bugs when trying to save a tensorflow model using pickle, and same appears to be when saving to a .h5 file. The only way I found right now is:
1- Save the structure to a JSON file
2- Save the weights in a .h5 file
3- Load back the structure
4- Load back the weights
5.1- (Optional, depend on the method) Assume a loss function and optimizer (since they are not savec)
5- Pass all of this in a function called by the KerasClassifier constructor
6- Manually defining the inner model by calling the build_fn method (otherwise we need to call the fit() method and thus assume the loss function and optimizer like if the training was not already done)
7- Then we have our KerasClassifier, that we can pass through the ANN_OM.saveParams, but we lack a lot of infos..
I am not an expert unfortunately, though I think there might be a more elegant solution, but right now it is the only way I found. I would happily request your thoughts on this.

Best,

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

No branches or pull requests

2 participants