我正在使用TensorFlow版本2.0.0和Python版本3.7.3。我尝试导入以下语句:
from tensorflow.contrib import rnn
它报错了,显示"Module 'tensorflow' has no attribute 'contrib'"。我该怎么解决?
我正在使用TensorFlow版本2.0.0和Python版本3.7.3。我尝试导入以下语句:
from tensorflow.contrib import rnn
它报错了,显示"Module 'tensorflow' has no attribute 'contrib'"。我该怎么解决?
来自TensorFlow
https://www.tensorflow.org/guide/upgrade#compatibility_modules
由于TensorFlow 2.x模块的弃用(例如tf.flags和tf.contrib),一些更改无法通过切换到compat.v1来解决。升级此代码可能需要使用其他库(例如absl.flags)或切换到tensorflow/addons软件包。https://github.com/tensorflow/tensorflow/issues/31350#issuecomment-518749548
我没有使用过较旧版本的TensorFlow。这是你要寻找的吗?
from tensorflow.keras.layers import RNN
关于contrib的信息:
https://www.tensorflow.org/guide/migrate#a_note_on_slim_contriblayers
AttributeError: module 'tensorflow_core._api.v2.nn' has no attribute 'rnn_cell'
。实际上,我正在尝试像这样做:self.cell = tf.nn.rnn_cell.BasicLSTMCell
。 - kritiimport tensorflow.keras.layers as layers
then...
self.cell = layers.LSTMCell(units=units, activation=activation, dropout=dropout)
- bug_spray
tensorflow.py
,请选择一个不同的名字。 - user2357112