keras 找不到具有tensorflow-macos的批次标准化

deyfvvtc  于 2022-11-13  发布在  Mac
关注(0)|答案(1)|浏览(173)

我在Nvidia GPU上有工作代码,但现在我转移到了我的Mac M1上。虽然找到了GPU,并且安装了tensorflow,但当我想导入BatchNormalization层时,我得到了以下错误:

from tensorflow.python.keras.layers import BatchNormalization

导入错误:无法从“tensorflow.python.keras.layers”导入名称“批处理规范化”(/用户/用户名/miniforge 3/环境/tensorflow环境38/lib/python3. 8/站点包/tensorflow/python/keras/layers/init.py)
以下是已安装的软件包:

Package                       Version
----------------------------- -------------------
absl-py                       1.0.0
appnope                       0.1.2
argon2-cffi                   21.3.0
argon2-cffi-bindings          21.2.0
asttokens                     2.0.5
astunparse                    1.6.3
attrs                         21.4.0
backcall                      0.2.0
backports.functools-lru-cache 1.6.4
black                         22.1.0
bleach                        4.1.0
cached-property               1.5.2
cachetools                    5.0.0
certifi                       2021.10.8
cffi                          1.15.0
charset-normalizer            2.0.12
click                         8.0.4
cycler                        0.11.0
dataclasses                   0.8
debugpy                       1.5.1
decorator                     5.1.1
defusedxml                    0.7.1
dill                          0.3.4
efficientnet                  1.0.0
entrypoints                   0.4
executing                     0.8.3
flatbuffers                   2.0
flit_core                     3.7.1
fonttools                     4.29.1
gast                          0.5.3
google-auth                   2.6.0
google-auth-oauthlib          0.4.6
google-pasta                  0.2.0
googleapis-common-protos      1.55.0
grpcio                        1.44.0
h5py                          3.6.0
idna                          3.3
image-classifiers             1.0.0
imageio                       2.16.1
importlib-metadata            4.11.2
importlib-resources           5.4.0
ipykernel                     6.9.1
ipython                       8.0.1
ipython-genutils              0.2.0
ipywidgets                    7.6.5
jedi                          0.18.1
Jinja2                        3.0.3
joblib                        1.1.0
jsonschema                    4.4.0
jupyter                       1.0.0
jupyter-client                7.1.2
jupyter-console               6.4.0
jupyter-core                  4.9.2
jupyterlab-pygments           0.1.2
jupyterlab-widgets            1.0.2
keras                         2.8.0
Keras-Applications            1.0.8
Keras-Preprocessing           1.1.2
kiwisolver                    1.3.2
libclang                      13.0.0
Markdown                      3.3.6
MarkupSafe                    2.1.0
matplotlib                    3.5.1
matplotlib-inline             0.1.3
mistune                       0.8.4
mypy-extensions               0.4.3
nbclient                      0.5.11
nbconvert                     6.4.2
nbformat                      5.1.3
nest-asyncio                  1.5.4
networkx                      2.7.1
notebook                      6.4.8
numpy                         1.21.5
oauthlib                      3.2.0
opencv-python                 4.5.5.64
opt-einsum                    3.3.0
packaging                     21.3
pandas                        1.4.1
pandocfilters                 1.5.0
parso                         0.8.3
patchify                      0.2.3
pathspec                      0.9.0
pexpect                       4.8.0
pickleshare                   0.7.5
Pillow                        9.0.1
pip                           22.0.3
platformdirs                  2.5.1
prometheus-client             0.13.1
promise                       2.3
prompt-toolkit                3.0.27
protobuf                      3.19.4
ptyprocess                    0.7.0
pure-eval                     0.2.2
pyasn1                        0.4.8
pyasn1-modules                0.2.8
pycparser                     2.21
Pygments                      2.11.2
pyparsing                     3.0.7
pyrsistent                    0.18.1
python-dateutil               2.8.2
pytz                          2021.3
PyWavelets                    1.3.0
pyzmq                         22.3.0
requests                      2.27.1
requests-oauthlib             1.3.1
rsa                           4.8
scikit-image                  0.19.2
scikit-learn                  1.0.2
scipy                         1.8.0
segmentation-models           1.0.1
Send2Trash                    1.8.0
setuptools                    60.9.3
six                           1.15.0
sklearn                       0.0
stack-data                    0.2.0
tensorboard                   2.8.0
tensorboard-data-server       0.6.1
tensorboard-plugin-wit        1.8.1
tensorflow-datasets           4.5.2
tensorflow-macos              2.8.0
tensorflow-metadata           1.7.0
tensorflow-metal              0.4.0
termcolor                     1.1.0
terminado                     0.13.1
testpath                      0.6.0
tf-estimator-nightly          2.8.0.dev2021122109
threadpoolctl                 3.1.0
tifffile                      2022.2.9
tomli                         2.0.1
tornado                       6.1
tqdm                          4.63.0
traitlets                     5.1.1
typed-ast                     1.5.2
typing_extensions             4.1.1
urllib3                       1.26.8
wcwidth                       0.2.5
webencodings                  0.5.1
Werkzeug                      2.0.3
wheel                         0.37.1
widgetsnbextension            3.5.2
wrapt                         1.13.3
zipp                          3.7.0

我找不到任何替代层来替换,有什么办法吗?

vdzxcuhz

vdzxcuhz1#

请按照以下代码检查您的系统中是否安装了tensorflow:

import tensorflow as tf
print(tf.__version__)

如果输出显示为version: 2.8.0,这意味着tensorflow已成功安装并导入到您的系统中,现在您可以将keras库从tensorflow导入为tensorflow.keras
在这里,您需要提供正确的别名以导入BatchNormalization,如this链接中所述。

from tensorflow.keras.layers import BatchNormalization

如果问题仍然存在,请告诉我们。谢谢。

相关问题