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

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

第一次遇见这个问题。

Python Tensor Flow Training- Value Error: Tensor must be from the same graph as Tensor_第1张图片

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])

你可能感兴趣的:(Python Tensor Flow Training- Value Error: Tensor must be from the same graph as Tensor)