简体   繁体   English

深度学习 Python Tensorflow,Keras

[英]Deeplearning with Python Tensorflow,Keras

I am writing masters thesis about deeplearning and have a problem probably about library.我正在写关于深度学习的硕士论文,可能对图书馆有疑问。

Below is the error:以下是错误:

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

Model: Model:

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

I think that the problem lies in the way you are importing the modules you need.我认为问题在于您导入所需模块的方式。 Try to do this way:尝试这样做:

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

If you get the summary of your network it means that everything is working fine, otherwise it could me that you haven't installed Tensorflow properly.如果您获得网络摘要,则表示一切正常,否则可能是您没有正确安装 Tensorflow。

For reference this is the summary:供参考,这是摘要:

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
_________________________________________________________________

most likely is the version of tensorflow you are using You just need to uninstall all keras and tensorflow packages and install the versions supported by Retin.net.很可能是您正在使用的 tensorflow 版本您只需要卸载所有 keras 和 tensorflow 软件包并安装 Retin.net 支持的版本。

!pip uninstall keras -y !pip uninstall keras-nightly -y !pip uninstall keras-Preprocessing -y !pip uninstall keras-vis -y !pip uninstall tensorflow -y !pip 卸载 keras -y !pip 卸载 keras-nightly -y !pip 卸载 keras-Preprocessing -y !pip 卸载 keras-vis -y !pip 卸载 tensorflow -y

.pip install tensorflow==2.3.0 !pip install keras==2.4 .pip 安装 tensorflow==2.3.0 !pip 安装 keras==2.4

Just add this to the top of your colab notebook and restart your runtime once its completed and then you are good to go只需将其添加到您的 colab 笔记本的顶部,并在完成后重新启动您的运行时,然后您就可以使用 go

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

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