导入库时出现错误:importError: cannot import name 'LayerNormalization' from 'tensorflow.python.keras.layers.normalization'
在自己笔记本上的深度学习环境中运行CycleGAN网络没有错误,但是显存不够,环境:
Python3.8
Tensorflow2.6.0
keras2.6.0
转到工作站运行,工作站当时下载了深度学习环境是:
Python3.8
Tensorflow2.3.0
keras2.4.3
问题描述:在keras第一次导入时出现错误
Using TensorFlow backend. 2021-05-15 20:43:16.281415: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll Traceback (most recent call last): File "E:/FACULTATE ANUL 3 SEMESTRUL 2/Procesarea Imaginilor/proiect/main.py", line 8, infrom keras.layers import Conv2D,Dropout, Flatten, Dense,MaxPooling2D, MaxPool2D File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packageskeras__init__.py", line 3, in from . import utils File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packageskerasutils__init__.py", line 6, in from . import conv_utils File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packageskerasutilsconv_utils.py", line 9, in from .. import backend as K File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packageskerasbackend__init__.py", line 1, in from .load_backend import epsilon File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packageskerasbackendload_backend.py", line 90, in from .tensorflow_backend import * File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packageskerasbackendtensorflow_backend.py", line 5, in import tensorflow as tf File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflow__init__.py", line 41, in from tensorflow.python.tools import module_util as _module_util File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpython__init__.py", line 48, in from tensorflow.python import keras File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkeras__init__.py", line 25, in from tensorflow.python.keras import models File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkerasmodels.py", line 20, in from tensorflow.python.keras import metrics as metrics_module File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkerasmetrics.py", line 37, in from tensorflow.python.keras import activations File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkerasactivations.py", line 18, in from tensorflow.python.keras.layers import advanced_activations File "C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkeraslayers__init__.py", line 146, in from tensorflow.python.keras.layers.normalization import LayerNormalization importError: cannot import name 'LayerNormalization' from 'tensorflow.python.keras.layers.normalization' (C:UsersMy-PcAppDataLocalProgramsPythonPython38libsite-packagestensorflowpythonkeraslayersnormalization__init__.py)
解决办法:参考以下网站:https://stackoverflow.com/questions/67549661/importerror-cannot-import-name-layernormalization-from-tensorflow-python-ker/67667525
错误原因:以上链接中表明可能是Python/Tensorflow/keras的版本不匹配导致的
解决:将工作站的三者的版本改为自己电脑的版本就可以了。
所以最后工作站的环境配成了:
CUDA11.2
cuDNN8.2.0
Tensorflow2.6.0 Tensorflow-gpu2.6.0
python3.8.0
keras2.6.0
部分Python/Tensorflow/Keras的版本对应关系
但是更新一点的Tensorflow和keras的对应关系还没有找到。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)