无法从“keras.utils.layer_utils”导入名称“CallFunctionSpec”(/usr/local/lib/python3.9/dist-packages/keras/utils/layer_utils.py)

问题描述 投票:0回答:2

代码昨天运行良好 代码是:

from sklearn import metrics
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.models import Sequential
from tensorflow.python.keras.optimizers import Adam

显示的错误是:

ImportError                               Traceback (most recent call last)
<ipython-input-71-00e64660885b> in <cell line: 2>()
      1 from sklearn import metrics
----> 2 from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
      3 from tensorflow.keras.models import Sequential
      4 from tensorflow.python.keras.optimizers import Adam

7 frames
/usr/local/lib/python3.9/dist-packages/keras/saving/legacy/saved_model/utils.py in <module>
     28 from keras.utils import tf_contextlib
     29 from keras.utils.generic_utils import LazyLoader
---> 30 from keras.utils.layer_utils import CallFunctionSpec
     31 
     32 training_lib = LazyLoader("training_lib", globals(), "keras.engine.training")

ImportError: cannot import name 'CallFunctionSpec' from 'keras.utils.layer_utils' (/usr/local/lib/python3.9/dist-packages/keras/utils/layer_utils.py)

它说无法从“keras.utils.layer_utils”导入“CallFunctionSpec” 但我没有在其中使用 utils 我不需要其中的实用程序,我需要的是图层,但它在实用程序中显示错误

我应该怎么做才能解决

cannot import name 'CallFunctionSpec' from 'keras.utils.layer_utils'
并且此错误已多次出现

python tensorflow machine-learning keras
2个回答
0
投票

要解决此问题,您必须将 keras 和 TensorFlow 升级到最新版本。您可以使用以下命令来完成此操作:

pip install --upgrade keras tensorflow

0
投票

我的keras版本是2.15.0 更改 --> from keras.src.utils.layer_utils import CallFunctionSpec 它对我有用

© www.soinside.com 2019 - 2024. All rights reserved.