Cant import tensorflow_model_optimization

Viewed 52

I got an error when try to import the tensorflow_model_optimization package When i run:

import tensorflow_model_optimization as tfmot

I got the following ERROR:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\__init__.py", line 86, in <module>
from tensorflow_model_optimization.python.core.api import clustering
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\api\__init__.py", line 16, in <module>
from tensorflow_model_optimization.python.core.api import clustering
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\api\clustering\__init__.py", line 16, in 
<module>
from tensorflow_model_optimization.python.core.api.clustering import keras
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\api\clustering\keras\__init__.py", line 19, 
in <module>
from tensorflow_model_optimization.python.core.clustering.keras.cluster import cluster_scope
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\clustering\keras\cluster.py", line 20, in 
<module>
from tensorflow_model_optimization.python.core.clustering.keras import cluster_wrapper
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\clustering\keras\cluster_wrapper.py", line 
24, in <module>
from tensorflow_model_optimization.python.core.clustering.keras import clustering_registry
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\clustering\keras\clustering_registry.py", 
line 57, in <module>
class ClusteringRegistry(object):
File "C:\Users\Asura\AppData\Local\Programs\Python\Python310\lib\site- 
packages\tensorflow_model_optimization\python\core\clustering\keras\clustering_registry.py", 
line 92, in ClusteringRegistry
tf.keras.experimental.PeepholeLSTMCell,
AttributeError: module 'keras.api._v2.keras.experimental' has no attribute 'PeepholeLSTMCell'

I have this error on different OS-es and with different python versions. I suspect it is a version error of some of the tf packages. The versions I use:

tensorflow                    2.9.1
tensorflow-addons             0.16.1
tensorflow-estimator          2.9.0
tensorflow-hub                0.12.0
tensorflow-io                 0.23.1
tensorflow-io-gcs-filesystem  0.23.1
tensorflow-model-optimization 0.7.1
1 Answers

I successfully imported tensorflow_model_optimization in my environment having the following versions:

tensorflow                    2.8.2
tensorflow-addons             0.17.1
tensorflow-estimator          2.8.0
tensorflow-hub                0.12.0
tensorflow-io                 0.26.0
tensorflow-io-gcs-filesystem  0.26.0
tensorflow-model-optimization 0.7.3

Related to Tensorflow I have the additional packages:

tensorflow-datasets           4.0.1 
tensorflow-gcs-config         2.8.0  
tensorflow-metadata           1.9.0
tensorflow-probability        0.16.0  

Hope this helps!

Related