python - 如何修复 : AttributeError: module 'tensorflow' has no attribute 'optimizers' in JupyterNotebook (using colab. 研究)

标签 python tensorflow jupyter-notebook google-colaboratory attributeerror

我试图在 colab.research 页面中运行我的神经网络,但我仍然收到错误 AttributeError: module 'tensorflow' has no attribute 'optimizers' at this line:

opt = tensorflow.optimizers.RMSprop(learning_rate=0.00001, decay=1e-6)

我从代码中导入的部分:

import tensorflow
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D
from keras import optimizers
import os

Tensorflow 版本:

print(tensroflow.__version__) # 1.15.0

最佳答案

优化器是 keras 库的一部分。要么做

from tensorflow.keras import optimizers

然后使用

optimizers.RMSprop()

在你的代码中 或者

opt = tensorflow.keras.optimizers.RMSprop()

关于python - 如何修复 : AttributeError: module 'tensorflow' has no attribute 'optimizers' in JupyterNotebook (using colab. 研究),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58837321/

相关文章:

python - zmq.error.ZMQError : Address already in use, 使用 papermill 对多个笔记本运行多处理时

python - 使用 boto3 和 python 从 amazon s3 读取 zip 文件

python - 将数据框从一个 Jupyter Notebook 文件导入到另一个文件

python - Django 日期时间不验证正确

tensorflow - keras Conv2d值错误: Negative dimension size

python - Tensorflow v1.14 中的梯度裁剪错误

tensorflow - Tensorflow 2.0.0-alpha 0 版本中已弃用函数的问题

python - Docker 容器中的 Jupyter 笔记本不持久?

python - 绘制 NetworkX Girvan-Newman 算法找到的社区的树状图

python - 在 Python 3 中检测类(不是实例)中的绑定(bind)方法