def buildRNN(self,x,scope):
print(x)
x = tf.transpose(x, [1, 0, 2])
#print(x)
x = tf.reshape(x, [-1,self.nfeatures])
#print(x)
x = tf.split(x, self.n_steps, 0)
print(x)
#lstm_cell = rnn.MultiRNNCell([rnn.BasicLSTMCell(self.n_hidden, forget_bias=1.0) for _ in range(self.n_layers)], state_is_tuple=True)
#outputs, states = tf.nn.dynamic_rnn(lstm_cell, x, dtype=tf.float64)
with tf.name_scope("fw"+scope),tf.variable_scope("fw"+scope):
fw_cell_array = []
print(tf.get_variable_scope().name)
for _ in range(self.n_layers):
fw_cell = rnn.BasicLSTMCell(self.n_hidden, forget_bias=1.0, state_is_tuple=True)
#fw_cell = rnn.DropoutWrapper(fw_cell,output_keep_prob=self.dropout)
fw_cell_array.append(fw_cell)
fw_cell = rnn.MultiRNNCell(fw_cell_array, state_is_tuple=True)
with tf.name_scope("bw"+scope),tf.variable_scope("bw"+scope):
bw_cell_array = []
print(tf.get_variable_scope().name)
for _ in range(self.n_layers):
bw_cell = rnn.BasicLSTMCell(self.n_hidden, forget_bias=1.0, state_is_tuple=True)
#bw_cell = rnn.DropoutWrapper(bw_cell,output_keep_prob=self.dropout)
bw_cell_array.append(bw_cell)
bw_cell = rnn.MultiRNNCell(bw_cell_array, state_is_tuple=True)
outputs, _,_ = tf.contrib.rnn.static_bidirectional_rnn(fw_cell, bw_cell, x, dtype=tf.float64)
#outputs, = tf.nn.bidirectional_dynamic_rnn(fw_cell, bw_cell, x, dtype=tf.float64)
print(outputs)
print(outputs[-1])
return outputs[-1]
siamese_lstm_network.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录