使用CudnnLSTM会出现以下错误:没有名为';tensorflow.contrib';卡格尔核

使用CudnnLSTM会出现以下错误:没有名为';tensorflow.contrib';卡格尔核,tensorflow,keras,kaggle,Tensorflow,Keras,Kaggle,我正试图在kaggle kerne上运行我的代码。这是我在keras的模型 inp = Input(shape=(maxlen,)) emb = Embedding(max_features, embed_size, weights=[embedding_matrix], trainable=False)(inp) x2 = Bidirectional(CuDNNGRU(64, return_sequences=True))(x1) max_pl = GlobalMaxPooling1D()(x

我正试图在kaggle kerne上运行我的代码。这是我在keras的模型

inp = Input(shape=(maxlen,))
emb = Embedding(max_features, embed_size, weights=[embedding_matrix], trainable=False)(inp)
x2 = Bidirectional(CuDNNGRU(64, return_sequences=True))(x1)
max_pl = GlobalMaxPooling1D()(x2)
x = Dense(16, activation="relu")(max_pl)
x = Dropout(0.1)(x)
output = Dense(1, activation="sigmoid")(x)

model = Model(inputs=inp, outputs=output)
但是因为cudngru,我没有得到名为“tensorflow.contrib”的模块。
我应该如何在kaggle内核上修复这个问题?

我根据您的结构在kaggle中创建了这个快速示例。请注意cudngru的名称。我希望这有帮助

import tensorflow as tf

inp = tf.keras.layers.Input(shape=(10,))
emb = tf.keras.layers.Embedding(20, 4)(inp)
x2 = tf.keras.layers.Bidirectional(tf.compat.v1.keras.layers.CuDNNGRU(64, return_sequences=True))(emb)
max_pl = tf.keras.layers.GlobalMaxPooling1D()(x2)
x = tf.keras.layers.Dense(16, activation="relu")(max_pl)
x = tf.keras.layers.Dropout(0.1)(x)
output = tf.keras.layers.Dense(1, activation="sigmoid")(x)

model = tf.keras.models.Model(inputs=inp, outputs=output)
model.summary()