简体   繁体   English

无法使用 CNN model 导入 keras

[英]failed to import keras with CNN model

from tensorflow.keras.models import Sequential
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers import MaxPool2D
from keras.layers.core import Activation, Flatten, Dropout, Dense
from tensorflow.keras import backend as K
import keras

the code can't read convolution, Batchnormaliztion, maxpool2D and etc.该代码无法读取卷积、Batchnormaliztion、maxpool2D 等。

I got this error:我收到了这个错误:

No module named 'module 'tensorflow' has no attribute 'get_default_graph''

If the error No module named 'module 'tensorflow' most probably you need to install it correctly.如果错误No module named 'module 'tensorflow'很可能你需要正确安装它。

If the error is module 'tensorflow' has no attribute 'get_default_graph' : first you need to unify the imports either use keras or tensorflow.keras如果错误是module 'tensorflow' has no attribute 'get_default_graph' :首先您需要统一导入使用kerastensorflow.keras

If the problem still exists try from tensorflow.python.keras import backend as k如果问题仍然存在,请尝试from tensorflow.python.keras import backend as k

I use tensorflow version 2.2.0.我使用 tensorflow 版本 2.2.0。 And it works, but instead:它有效,但相反:

 from keras.layers import MaxPool2D   

I use:我用:

from keras.layers import MaxPooling2D

I think you might have a problem with your Tensorflow module.我认为您的 Tensorflow 模块可能有问题。 Run the following code and see if it outputs you details about your Tensorflow Module:运行以下代码,看看它是否输出有关 Tensorflow 模块的详细信息:

pip show tensorflow

If this shows you details about your TensorFlow module, then you have installed it correctly.如果这显示了有关 TensorFlow 模块的详细信息,那么您已正确安装它。

I would suggest you use Anaconda for module management.我建议您使用 Anaconda 进行模块管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM