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

2024-09-29 02:21:56 发布

您现在位置:Python中文网/ 问答频道 /正文

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

以下是错误:

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))

Tags: fromimportaddmodel图书馆modelslayerstensorflow
1条回答
网友
1楼 · 发布于 2024-09-29 02:21:56

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

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
_________________________________________________________________

相关问题 更多 >