-
Notifications
You must be signed in to change notification settings - Fork 162
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 convert models saved using tensorflow.keras? #92
Comments
Yes, as of now I have not implemented support for loading from the tensorflow.keras saved file format. |
Thank you for a swift answer! I ran the training again for my network using keras instead of tensorflow.keras. However, when trying to calculate the importance scores as instructed in the "Quickstart"-section, I get a following error message:
This occurs when I try to compile the function to compute the contribution scores, i.e.
I was able to convert the model without issues with:
My model looks like this:
I am a little lost as to what the error message means. Am I setting the target layer index incorrectly? As far as I understand, the target layer should be layer "dense_1" (I am doing binary classification). But if I try:
I get the following error:
So maybe I cannot use BatchNormalization after the final dense layer? Sorry for a rather lengthy post, any help would be greatly appreciated :) |
Hi @hartonen, yes, the target layer should be dense_1 and you are doing things correctly. This one is my fault; that "RuntimeError" should just be a warning because I put it in to catch cases where people accidentally specified the wrong index for the target layer (e.g. because they copied the settings from the quickstart without adjusting the settings for their specific architecture). I was not expecting an architecture like yours where batchnorm is applied to the very last layer. I have made a pull request where I change the error to just be a warning at https://github.com/kundajelab/deeplift/pull/93/files - could you try it out and see if it addresses your issues? If so, I can merge it into the master branch. |
Hi @AvantiShri and thank you for taking the time to make the pull request! When trying out the pull request you linked, I ran into another problem. It seems that I am only able to convert my model using deeplift version 0.6.9.0, but if I try newer versions I get an error. Here is first the output when using deeplift 0.6.9.0 (this is the release I had installed):
Then opening ipython and converting the keras model to deeplift model:
So the model is converted nicely! Then if I install the newest version of deeplift (this is also the version I get when I clone deeplift repo and do 'pip install --editable', which I did before trying the pull request):
I get the following error:
And weirdly enough now, python claims the version is 0.6.8.1:
even though pip says it is 0.6.9.1:
The virtual environment used is otherwise identical in test made with deeplift versions 0.6.9.1 and 0.6.9.0. My model does not use bias terms in convolutional filters so could this be something that in version 0.6.9.1 this is required? Or have I somehow messed up my installation since after installing the version 0.6.9.1 with pip, python still claims the deeplift version is 0.6.8.1? |
Hi @hartonen, Don’t worry about “0.6.8.1” showing up when you do I am surprised that the model conversion worked with v0.6.9.0 because I would have expected that error to be thrown if you supplied a model that had no bias terms even with v0.6.9.0. I can make a fix that would avoid the error. Can you upload a saved model file so I can try reproducing the error? As an aside, the latest version on the master branch is v0.6.9.2, and the version on the branch I made for you is v0.6.9.3, so I think you may not have done a “git pull” to get the latest version - however I think even if you had, you would have still gotten the error, which is why I am requesting a model file for debugging purposes (if you don’t want to share your actual model that’s fine; any model that can reproduce the error would do). |
Ok, I pushed some updates to #93 that should address the error. You could test it out on your computer (remember to switch to the targetlayerwarningfix branch), and if you have any issues feel free to upload a model that I could use for testing purposes |
Hi @AvantiShri and thanks again for your response and help! So I have now cloned the latest version of deeplift repo and swithced to branch targetlayerwarningfix:
These are the packages and their versions I have installed:
This is the output I get when trying to convert my model using the branch targetlayerwarningfix:
I have truncated the error message as it is quite long.
Anyway, the conversion works with otherwise the same setup when I replace the latest version of deeplift with the version 0.6.9.0. I have attached below a model that should reproduce the error as a .gz-file. Structure of the model should look like this:
This is the gz-file contianing my model, let e know if it does not work: model-02-0.75.h5.gz |
Thanks for the info. I pushed a fix for the |
Hi @AvantiShri , I pulled the latest fixes for branch targetlayerwarningfix, and this is the output I get when trying to convert my model:
Hopefully this is of help! |
Hello @hartonen, I implemented a fix and tested it out with your model: https://colab.research.google.com/gist/AvantiShri/d3344f1c3a64354d397b621a889c21ce/testingnobiasfix.ipynb - the model conversion and If this works for you, I will merge the feature into the master branch. As an aside, it turns out that the reason it worked with v0.6.9.0 on pypi is that I had accidentally created that pypi build from a different branch than the master branch, and that different branch had some extra features (including this fix). I didn't finish working on those features and created the build for subsequent versions from the master branch, which is why they did not contain this fix. Thanks for your patience, |
Hi @AvantiShri , I pulled the new fixes and I can confirm that I was able to convert my model and to calculate importance scores. So everything seems to be working. Thank you very much for taking the time to look at my issues! Cheers, |
Thank you for a very useful tool!
Am I correct in assuming that models saved using tensorflow.keras are not supported? Is the only way to visualize these models to manually create an identical model in keras and load the weights from my model saved with tensorflow.keras (as done in deeplift/examples/convert_models/keras1.2to2/MNIST.ipynb)? Just wanted to make this sure for myself :)
The text was updated successfully, but these errors were encountered: