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

How to get trained model in keras format instead of saved model? #64

Open
DamRsn opened this issue Feb 26, 2023 · 3 comments
Open

How to get trained model in keras format instead of saved model? #64

DamRsn opened this issue Feb 26, 2023 · 3 comments
Assignees

Comments

@DamRsn
Copy link

DamRsn commented Feb 26, 2023

Thanks for this amazing work!

I'm currently working on integrating basic-pitch in an audio plugin. For that, I would need to have the trained basic pitch model as a Keras model in order to convert it into the format that I'm going to use in C++ for inference.

Unfortunately, the ICASSP2022 model is saved as a tensorflow saved_model, even though it is originally a keras model that can be built with the model() function from model.py.

I tried to transfer the weights from the trained model to an untrained keras model but I did not find a straightforward way to do it.

I could gather all the layers' weights manually from the saved_model and apply them one by one to an untrained keras model created with model(), but before getting there: do you have a trained keras model that you could share? Or do you know a way to get it from the trained tensorflow saved_model?

Also, similar to #62 , is there a more recent model I could use, perhaps the one used in the basic-pitch-ts repo for https://basicpitch.spotify.com/ ?

Thanks for your help!

@achimmihca
Copy link

achimmihca commented May 21, 2023

I successfully converted the saved_model format of basic pitch to onnx format using tf2onnx.

You could try to further convert this onnx model to keras using onnx2keras.

@DamRsn
Copy link
Author

DamRsn commented May 21, 2023

On my side, I managed to apply the weights of the tfjs model (model used in the basic-pitch website) to the keras model (created with model()). I did it by manually exporting the weights of each layer to .npy using the Netron App and then applying them using .setWeights() for each layer.

Converting to ONNX definitely helps, but I don't think you'll get the same structure for the keras model as the one you get when you create the keras model using model(), it will be much more messy. Plus you need a way to separate the CQT computation part of the network and the actual CNN.

All those issues would be solved if the model was saved directly with the keras API after training, but I don't know if it is that easy to do once the model is trained and saved as a .saved_model.

@dpl123
Copy link

dpl123 commented May 22, 2023

Agree, amazing for sure! @DamRsn very cool plugin too!!

Another vote for getting some kind of more usable model format. Any assistance would be appreciated with this

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

4 participants