当前位置: 代码迷 >> 综合 >> Python Tensor Flow Training- Value Error: Tensor must be from the same graph as Tensor
  详细解决方案

Python Tensor Flow Training- Value Error: Tensor must be from the same graph as Tensor

热度:49   发布时间:2023-12-13 11:48:12.0

Python Tensor Flow Training- Value Error: Tensor must be from the same graph as Tensor

  • 第一次遇见这个问题。
    • BiLSTM
  • sequence_length = length,

第一次遇见这个问题。

在这里插入图片描述

BiLSTM

// An highlighted block
with tf.variable_scope("bi-lstm"):_fw_cell = tf.nn.rnn_cell.LSTMCell(hidden_size, initializer=initializer())fw_cell = tf.nn.rnn_cell.DropoutWrapper(_fw_cell, self.rnn_dropout_keep_prob)_bw_cell = tf.nn.rnn_cell.LSTMCell(hidden_size, initializer=initializer())bw_cell = tf.nn.rnn_cell.DropoutWrapper(_bw_cell, self.rnn_dropout_keep_prob)self.rnn_outputs, _ = tf.nn.bidirectional_dynamic_rnn(cell_fw=fw_cell,cell_bw=bw_cell,inputs=self.X,sequence_length = length,time_major=False,dtype=tf.float32)self.rnn_outputs = tf.add(self.rnn_outputs[0], self.rnn_outputs[1])

sequence_length = length,

在函数外定义了,length = tf.constant(384, shape=[50]),所以报错:‘Python Tensor Flow Training- Value Error: Tensor must be from the same graph as Tensor’

尝试这样改


graph = tf.Graph()with graph.as_default():length = tf.constant(384, shape=[50])
  相关解决方案