Giter VIP home page Giter VIP logo

Comments (13)

jkparuchuri avatar jkparuchuri commented on May 22, 2024 2

@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.

alanchiao avatar alanchiao commented on May 22, 2024 1

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.

jkparuchuri avatar jkparuchuri commented on May 22, 2024 1

@alanchiao Able to resolve the issue. Its "tf.compat.v1.keras.layers.BatchNormalization: []". keras was missing earlier in that line.

from model-optimization.

alanchiao avatar alanchiao commented on May 22, 2024

@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.

alanchiao avatar alanchiao commented on May 22, 2024

Making a documentation update in #225.

from model-optimization.

jkparuchuri avatar jkparuchuri commented on May 22, 2024

@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.

jkparuchuri avatar jkparuchuri commented on May 22, 2024

@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.

alanchiao avatar alanchiao commented on May 22, 2024

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.

jkparuchuri avatar jkparuchuri commented on May 22, 2024

@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.

alanchiao avatar alanchiao commented on May 22, 2024

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.

jkparuchuri avatar jkparuchuri commented on May 22, 2024

@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.

alanchiao avatar alanchiao commented on May 22, 2024

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.

bilalahmed381 avatar bilalahmed381 commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.