Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.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
Python Tensorflow错误:尝试使用未初始化的值多单元_Python_Tensorflow_Machine Learning_Deep Learning_Recurrent Neural Network - Fatal编程技术网

Python Tensorflow错误:尝试使用未初始化的值多单元

Python Tensorflow错误:尝试使用未初始化的值多单元,python,tensorflow,machine-learning,deep-learning,recurrent-neural-network,Python,Tensorflow,Machine Learning,Deep Learning,Recurrent Neural Network,在我的模型文件中,我创建了一个多层rnn,如下所示: #RNN initialization part cell = tf.contrib.rnn.GRUCell(self.global_dim, kernel_initializer=self.xavier_initializer) self.GRU = tf.contrib.rnn.MultiRNNCell([cell for _ in range(self.rnn_layers)]) 我在另一个函数中调用此单元格: def RNN(

在我的模型文件中,我创建了一个多层rnn,如下所示:

#RNN initialization part
cell = tf.contrib.rnn.GRUCell(self.global_dim, kernel_initializer=self.xavier_initializer)   
self.GRU = tf.contrib.rnn.MultiRNNCell([cell for _ in range(self.rnn_layers)])
我在另一个函数中调用此单元格:

def RNN(self):
    state = self.initRNNState()
    inputs = tf.reshape(self.itemVec, [self.num_steps, self.batch_size, self.global_dim])
    hiddenState = []

    for time_step in range(self.num_steps):
        _, state = self.GRU(inputs[time_step], state)
        hiddenState.append(tf.reshape(state[-1], [self.global_dim])) #Store last layer

    return tf.convert_to_tensor(hiddenState)
在我的主文件中,我尝试了
sess.run(tf.global\u variables\u initializer())
sess.run(tf.local\u variables\u initializer())
,但得到了相同的eror:

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value multi_rnn_cell/cell_0/gru_cell/gates/kernel
     [[Node: multi_rnn_cell/cell_0/gru_cell/gates/kernel/read = Identity[T=DT_FLOAT, _class=["loc:@multi_rnn_cell/cell_0/gru_cell/gates/kernel"], _device="/job:localhost/replica:0/task:0/device:GPU:0"](multi_rnn_cell/cell_0/gru_cell/gates/kernel)]]
     [[Node: Neg/_11 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_1304_Neg", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

我只是想知道为什么我的gru单元格没有初始化。

您没有显示完整的代码,但我确信您首先调用了
sess.run(tf.global\u variables\u initializer())
,然后调用
RNN()
方法。这不起作用,因为
RNN()
正在向图中添加新节点,它们需要初始化,就像其他节点一样


解决方案:确保您创建了完整的计算图,然后才调用初始值设定项。

是的,您的猜测是正确的!我想我知道如何运行我的图表。