-
Notifications
You must be signed in to change notification settings - Fork 326
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
prune_low_magnitude retruns None #12
Comments
How do you solve it? I encounter the similar problem and could you help me? |
Make sure you're using Keras from Tensorflow-Python. Try this: |
This did not seem to work for me. What version of Keras is considered correct? |
Did you ever find a solution to this problem? |
You want to be using tf.keras for all sequential models. |
Yes, I am getting a NoneType returned from prune_low_magnitude. Here is my output: Here is the pruning code I am working with: When putting a breakpoint on the compile, where I am getting the error, I see that the new_model is None. These are the imports I am using for the model I am training and attempting to prune: Is this the incorrect way to go about it? |
Your imports look fine to me. Check the type of the model you generated: type(my_model) and lmk what the output is, it should be a tf.keras Model - it cannot be a Sequential Model, you need to convert it. This source code explains why you're getting a NoneType returned:
Btw, just outta curiosity what do you plan on using pruning for? With this package as it is, you're only going to save footprint size when using a compression utility (e.g gzip). You're also not going to obtain any faster inference time, unless you've enabled some sort of meta parameter on your hardware device. |
You can convert it like this:
|
This revealed the problem to me. I was returning my model incorrectly. I was not using the getter method in my custom class that contained my model. Thank you so much! |
@blakeedwards823 : it works with pruning a Sequential model. Sequential is an instance of keras.Model (see these docs). |
The pruned model type is <class 'NoneType'> |
Closing this issue since Blake has found a resolution here.
instead of
In other words, the actual Keras model object was not passed. I have filled an issue to add an error message when a Keras model object is not passed. @blakeedwards823 : if I'm wrong, please correct me and share the before/after code that demonstrates your resolution. @bothrasumit: let's move the discussion to your issue and see if Blake's problem is the same one you ran into from his response. |
I am trying to prune a trained model , but model is saved a model_architecture.json and weights.h5 and model is loaded as follows:
with open(modeljson) as f:
self.model = model_from_json(f.read())
self.model.load_weights(modelfile)
But whenever I try to prune it the output from:
new_pruned_model = sparsity.prune_low_magnitude(model, **new_pruning_params)
is always none so it crashes at the model.compile part as type none has no attribute compile
Any help please
The text was updated successfully, but these errors were encountered: