aymericdamien / TensorFlow-Examples

TensorFlow Tutorial and Examples for Beginners (support TF v1 & v2)
Other
43.44k stars 14.94k forks source link

How to copy variblaes in LSTM #355

Open tachiang opened 4 years ago

tachiang commented 4 years ago

There are two attention based seq2seq network implemented by tf.contrib.rnn (tensorflow 1.11) and they are of the same network architecture. One is evalation network and the other one is target network. The evalation network is updaed at each iteration and the target network copy weights (variables) from the evaluation network at every 1000 iterations. Since the varibales in LSTM seems to be not available to deginers, how to copy variables of the evaluation network to the target network?

######################################################## Key codes in evaluation network ######################################################## with tf.variable_scope('eval_net'): tf.contrib.rnn.LSTMCell(self.rnn_size) ... encoder_outputs, encoder_state = tf.nn.dynamic_rnn(enc_cell, encoder_inputs, enc_input_lens, dtype=tf.float32) ... my_decoder = tf.contrib.seq2seq.BasicDecoder(dec_cell, my_helper, decoder_initial_state, output_layer=output_layer # applied per timestep )
actoroutputs, , _ = tf.contrib.seq2seq.dynamic_decode(my_decoder, maximum_iterations=self.max_input_seq_len) ... ######################################################## Key codes in target network ######################################################## with tf.variable_scope('target_net'): tf.contrib.rnn.LSTMCell(self.rnn_size) ... encoder_outputs, encoder_state = tf.nn.dynamic_rnn(enc_cell, encoder_inputs, enc_input_lens, dtype=tf.float32) ... my_decoder = tf.contrib.seq2seq.BasicDecoder(dec_cell, my_helper, decoder_initial_state, output_layer=output_layer # applied per timestep )
actoroutputs, , _ = tf.contrib.seq2seq.dynamic_decode(my_decoder, maximum_iterations=self.max_input_seq_len) ...