Comments (13)
@Craftsman381 Workaround is to add "tf.compat.v1.keras.layers.BatchNormalization: []"
to prune_registry at https://github.com/tensorflow/model-optimization/blob/master/tensorflow_model_optimization/python/core/sparsity/keras/prune_registry.py#L82 and rebuild from source
from model-optimization.
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.
from model-optimization.
@alanchiao Able to resolve the issue. Its "tf.compat.v1.keras.layers.BatchNormalization: []". keras was missing earlier in that line.
from model-optimization.
@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.
from model-optimization.
Making a documentation update in #225.
from model-optimization.
@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 Prune
with a supported layer. Layers should either be a PrunableLayer
instance, or should be supported by the PruneRegistry. You passed: <class 'tensorflow.python.keras.saving.saved_model.load.ZeroPadding2D'>
from model-optimization.
@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.
INFO: Elapsed time: 0.083s
from model-optimization.
Can you cd out of tensorflow_model_optimization into the model-optimization folder? Then run the same command.
I realized that the cd tensorflow_model_optimization
instruction is incorrect. Should say cd model-optimization
.
from model-optimization.
@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.
ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/keras/BUILD:75:1: //tensorflow_model_optimization/python/core/clustering/keras:clustering_centroids_test: no such attribute 'python_version' in 'py_test' rule.
ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/keras/BUILD:87:1: //tensorflow_model_optimization/python/core/clustering/keras:cluster_wrapper_test: no such attribute 'python_version' in 'py_test' rule.
ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/keras/BUILD:103:1: //tensorflow_model_optimization/python/core/clustering/keras:clustering_registry_test: no such attribute 'python_version' in 'py_test' rule.
ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/keras/BUILD:9:1: Target '//tensorflow_model_optimization/python/core/clustering/keras:cluster' contains an error and its package is in error and referenced by '//tensorflow_model_optimization/python/core/clustering/keras:keras'.
ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/keras/BUILD:9:1: Target '//tensorflow_model_optimization/python/core/clustering/keras:init.py' contains an error and its package is in error and referenced by '//tensorflow_model_optimization/python/core/clustering/keras:keras'.
ERROR: /Users/jith/june/git/model-optimization/tensorflow_model_optimization/python/core/clustering/BUILD:5:1: Target '//tensorflow_model_optimization/python/core/clustering/keras:keras' contains an error and its package is in error and referenced by '//tensorflow_model_optimization/python/core/clustering:clustering'.
ERROR: Analysis of target '//:pip_pkg' failed; build aborted: Loading failed.
INFO: Elapsed time: 0.136s
from model-optimization.
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.
from model-optimization.
@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))
ValueError: Please initialize Prune
with a supported layer. Layers should either be a PrunableLayer
instance, or should be supported by the PruneRegistry. You passed: <class 'tensorflow.python.keras.layers.normalization.BatchNormalization'>
from model-optimization.
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.
from model-optimization.
Trying to prune Resnet50 and getting this error, can you tell me what't the solution of this.
ValueError: Please initialize Prune
with a supported layer. Layers should either be a PrunableLayer
instance, or should be supported by the PruneRegistry. You passed: <class 'tensorflow.python.keras.layers.normalization.BatchNormalization'>
from model-optimization.
Related Issues (20)
- QAT aware training for mobilenetV2 not working HOT 1
- Determinism is not yet supported in GPU implementation of FakeQuantWithMinMaxVarsGradient HOT 2
- batch norm layer quantization error HOT 2
- 16x8 Quantization fails for RNN model - Max and min for dynamic tensors should be recorded during calibration HOT 4
- float16 quantization runs out of memory for LSTM model HOT 3
- float16 quantization runs out of memory for LSTM model HOT 1
- Add a default PruningPolicy that filters out any layers not supported by the API HOT 1
- Add batch norm to default_n_bit_quantize_registry and default_8_bit_quantize_registry HOT 2
- Quant aware training in tensorflow model optimization HOT 4
- [COLAB] No module named 'tensorflow_model_optimization' HOT 1
- Module Import Error HOT 2
- A error about quantization aware training HOT 2
- MobileNetV3 QAT TFLite Conversion Issue HOT 4
- Error in MovingAverageQuantizer with per_axis=True due to missing parameters in _add_range_weights
- strange behavior when quantizing a model. HOT 2
- Support for Recurrent layers for Quantization Aware Training. HOT 1
- Can't use TFMOT version 0.8.0 due to missing dependency HOT 1
- Any plans to support keras3? HOT 3
- Cannot use Quantize layer and use abstract class and methods HOT 1
- Custom layer with Concat afterwards causes an error during QAT modeling HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from model-optimization.