Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow FailedPremissionError:从容器localhost读取资源变量module/bilm/CNN_proj/W_proj时出错_Tensorflow_Tensorflow Hub_Elmo - Fatal编程技术网

Tensorflow FailedPremissionError:从容器localhost读取资源变量module/bilm/CNN_proj/W_proj时出错

Tensorflow FailedPremissionError:从容器localhost读取资源变量module/bilm/CNN_proj/W_proj时出错,tensorflow,tensorflow-hub,elmo,Tensorflow,Tensorflow Hub,Elmo,我试图在jupyter notebook和python 3.7中使用经过预培训的elmo嵌入。 Tensorflow版本-1.14.0 这是我的密码 def ElmoEmbeddingLayer(x): print(x.shape) module = hub.Module("https://tfhub.dev/google/elmo/3", trainable=False) embeddings = module(tf.squeeze(tf.cast(x, tf.stri

我试图在jupyter notebook和python 3.7中使用经过预培训的elmo嵌入。 Tensorflow版本-1.14.0

这是我的密码

def ElmoEmbeddingLayer(x):
    print(x.shape)
    module = hub.Module("https://tfhub.dev/google/elmo/3", trainable=False)
    embeddings = module(tf.squeeze(tf.cast(x, tf.string)), signature="default", as_dict=True)["elmo"]
    return embeddings
elmo_dim=1024
elmo_input = Input(shape=(None,), dtype=tf.string)
elmo_embedding = Lambda(ElmoEmbeddingLayer, output_shape=(None,elmo_dim))(elmo_input)
x = Dense(1)(elmo_embedding)
x = Activation('relu')(x)
model = Model(inputs=[elmo_input], outputs=x)
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1,validation_data=(x_test, y_test))
但是我得到了一个运行时错误

FailedPremissionError:从容器localhost读取资源变量module/bilm/CNN_proj/W_proj时出错。这可能意味着变量未初始化。未找到:资源localhost/module/bilm/CNN_proj/W_proj/N10tensorflow3VarE不存在。 [{{node lambda/module\u apply\u default/bilm/MatMul\u 9/ReadVariableOp}}]


要在构建Keras模型时使用TF Hub中的模型件,请使用
Hub.KerasLayer
类。它实现了Keras收集初始化变量的方法。使用tensorflow_hub 0.7.0(最好是tensorflow 1.15),您还可以将其用于较旧的TF hub模块(如示例中的),但需要注意一些事项,请参阅

对于上下文:旧的
hub.Module
类用于以经典的TF1方式(如tf.layers)构建模型。它通过tf.Graph的GLOBAL_variables集合实现了收集用于初始化的变量的旧式方法。你的案子里没有这些。(您可以尝试在由
tf.compat.v1.keras.backend.get_Session()
返回的会话中手动初始化它们,但这有点奇怪。)