-
Notifications
You must be signed in to change notification settings - Fork 320
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
Pruning not working for tf.keras.Batchnorm #224
Comments
@jkparuchuri : how are you creating your batchnorm layer? In TF 2.1.0, the batchnorm layer class should be tensorflow.python.keras.layers.normalization_v2.BatchNormalization if you are using the tf.keras.layers.BatchNormalization API. If you are using tf.compat.v1.keras.layers.BatchNormalization in 2.1.0, that is currently not supported. I can update the documentation in that case. |
Making a documentation update in #225. |
@alanchiao I didnt use compat.v1 but the keras model was saved using .h5 format. Now I tried to save in in default saved model format and loaded for it. I gave a different error aa below. Any suggestions. Please initialize |
Thanks @jkparuchuri. Looks like the keras model was originally built in TF 1.X and saved using h5 and you are now reloading it in TF 2.X. This isn't a case I had considered actually and glad you brought it up. The same with regards to SavedModel (it uses different classes under the hood right now when compared to using the tf.keras.layers directly). In the mean time, a workaround (without needing the original model architecture) would be to modify this file and add a row below "layers.BatchNormalization: []" that says "tf.compat.v1.layers.BatchNormalization: []". Then build the pip package via https://github.com/tensorflow/model-optimization#installing-from-source. Keep using the h5 model in that case. If you're using one of the common vision models (e.g. mobilenet), that should suffice. I'll consider what is appropriate for your case. |
@alanchiao Building from source not working on my mac ITs giving error ERROR: no such target '//tensorflow_model_optimization:pip_pkg': target 'pip_pkg' not declared in package 'tensorflow_model_optimization' defined by /Users/jith/june/git/model-optimization/tensorflow_model_optimization/BUILD. |
Can you cd out of tensorflow_model_optimization into the model-optimization folder? Then run the same command. I realized that the |
@alanchiao Tried that but its giving different errors ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/keras/BUILD:63:1: //tensorflow_model_optimization/python/core/clustering/keras:cluster_test: no such attribute 'python_version' in 'py_test' rule. |
python_version is available in bazel since 0.22.0 (see https://docs.bazel.build/versions/0.22.0/be/python.html). Do you think you'd be able to upgrade your version of bazel? I'll need to take a look at the TFMOT docs and clarify the minimum bazel version also. |
@alanchiao Thankyou, upgrading bazel resolved the building from source. But still see the same error even after adding to registry as you suggested :( 'PruneRegistry. You passed: {input}'.format(input=layer.class)) |
I'd make sure that the tensorflow_model_optimization you're using is the one built from https://github.com/tensorflow/model-optimization#installing-from-source with your change as opposed to the one you previously installed that MOT provided. I'm pretty confident what I suggested was correct. |
@alanchiao Able to resolve the issue. Its "tf.compat.v1.keras.layers.BatchNormalization: []". keras was missing earlier in that line. |
Trying to prune Resnet50 and getting this error, can you tell me what't the solution of this.ValueError: Please initialize |
@Craftsman381 Workaround is to add |
Describe the bug
ValueError: Please initialize
Prune
with a supported layer. Layers should either be aPrunableLayer
instance, or should be supported by the PruneRegistry. You passed: <class 'tensorflow.python.keras.layers.normalization.BatchNormalization'>System information
TensorFlow installed from (source or binary): binary
TensorFlow version: 2.1.0
TensorFlow Model Optimization version: 0.2.1
Python version: 3.5.6
The text was updated successfully, but these errors were encountered: