Dav*_*vid 2 numpy python-3.x keras tensorflow
我正在使用一本《Deep Learning With Python》笔记本(第二版)
当我在单元格 1 中运行以下代码时——
from tensorflow.keras import layers
model = keras.Sequential([
layers.Dense(64, activation="relu"),
layers.Dense(10, activation="softmax")
])
Run Code Online (Sandbox Code Playgroud)
我立即收到此错误,我不知道如何修复:
/usr/local/lib/python3.8/dist-packages/tensorflow/python/framework/dtypes.py:585:
FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
np.object,
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_1679/4031490511.py in <module>
----> 1 from tensorflow import keras
2 from tensorflow.keras import layers
3
4 model = keras.Sequential([
5 layers.Dense(64, activation="relu"),
Run Code Online (Sandbox Code Playgroud)
...然后是一系列其他导入错误,然后是:
583 # strings.
584 types_pb2.DT_STRING:
--> 585 np.object,
586 types_pb2.DT_COMPLEX64:
587 np.complex64,
/usr/local/lib/python3.8/dist-packages/numpy/__init__.py in __getattr__(attr)
303
304 if attr in __former_attrs__:
--> 305 raise AttributeError(__former_attrs__[attr])
306
307 # Importing Tester requires importing all of UnitTest which is not a
AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
Run Code Online (Sandbox Code Playgroud)
然后我想我可能有一个旧版本的 Keras,所以我首先查看了 Keras 变更日志https://github.com/keras-team/keras/releases但我找不到任何与 numpy 或对象,所以我尝试从终端获取我正在使用的版本:
python3 -c 'import keras; print(keras.__version__)'
但它立即给了我同样的错误。
任何帮助表示赞赏!
小智 8
尝试numpy使用以下命令安装版本 1.23.4(这对我有用):
pip install numpy==1.23.4
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6215 次 |
| 最近记录: |