无法导入tensorflow_model_optimization

yv5phkfx  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(135)

我得到了一个错误,当尝试导入tensorflow_model_optimization包当我运行:

import tensorflow_model_optimization as tfmot

字符串
我得到了以下错误:

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'


我在不同的OS-es和不同的python版本上都有这个错误。我怀疑这是一些tf包的版本错误。我用途:

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

thtygnil

thtygnil1#

我成功地导入了tensorflow_model_optimization在我的环境中具有以下版本:

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

字符串
与Tensorflow相关,我有额外的包:

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


希望这对你有帮助!

wooyq4lh

wooyq4lh2#

确保您首先安装了tensorflow_model_optimization库

pip install tensorflow_model_optimization

字符串
然后运行:

import tensorflow_model_optimization as tfomt


也请确保升级keras版本

pip install --upgrade keras

相关问题