使用 Python Tensorflow、Keras 进行深度学习

时间:2021-06-10 07:04:56

标签: python tensorflow keras

我正在写关于深度学习的硕士论文,可能有关于图书馆的问题。

错误如下:

AttributeError: module 'tensorflow.compat.v2' has no attribute '__internal__'  

型号:

import tensorflow 
from tensorflow import  keras 
from keras import models  
from keras import layers  
model = models.Sequential()  
model.add(layers.Dense(32, input_shape=(784,)))  
model.add(layers.Dense(32))

1 个答案:

答案 0 :(得分:1)

我认为问题在于您导入所需模块的方式。尝试这样做:

import tensorflow  
from tensorflow.keras import models, layers  

model = models.Sequential()   
model.add(layers.Dense(32, input_shape=(784,)))   
model.add(layers.Dense(32))

model.summary()

如果您获得网络摘要,则意味着一切正常,否则可能是您没有正确安装 Tensorflow。

作为参考,这是摘要:

Layer (type)                 Output Shape              Param #
=================================================================
dense (Dense)                (None, 32)                25120
_________________________________________________________________
dense_1 (Dense)              (None, 32)                1056
=================================================================
Total params: 26,176
Trainable params: 26,176
Non-trainable params: 0
_________________________________________________________________