【问题标题】:Can not find BatchNormalization with tensorflow-macos使用 tensorflow-macos 找不到 BatchNormalization
【发布时间】:2022-10-18 19:04:02
【问题描述】:

我在 Nvidia GPU 上有工作代码,但现在我搬到了我的 Mac M1。尽管在我想导入 BatchNormalization 层时找到了 GPU 并安装了 tensorflow,但我收到以下错误:

from tensorflow.python.keras.layers import BatchNormalization

ImportError:无法从“tensorflow.python.keras.layers”导入名称“BatchNormalization”(/Users/user_name/miniforge3/envs/tensorflow_env_38/lib/python3.8/site-packages/tensorflow/python/keras/layers/在里面.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

我找不到任何替代层来替换,知道有什么解决方案吗?

【问题讨论】:

  • 不要使用 tensorflow.python.keras,只使用 tensorflow.keras
  • 它找不到 tensorflow.keras...
  • 这很奇怪,也许你的 tensorflow-macos 不知何故坏了?你应该问苹果
  • 我猜新版本有一个错误,最终降级到 tensorflow-deps==2.6 tensorflow-metal==0.4.0 解决了这个问题。

标签: python python-3.x tensorflow keras


【解决方案1】:

同样的问题,你现在解决了吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2016-12-18
    • 1970-01-01
    • 2022-10-15
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多