if __name__ == '__main__': train_config = TrainConfig() test_config = TestConfig()
# the wrong method to reuse parameters in train rnn with tf.variable_scope('train_rnn'): train_rnn1 = RNN(train_config) with tf.variable_scope('test_rnn'): test_rnn1 = RNN(test_config)
# the right method to reuse parameters in train rnn with tf.variable_scope('rnn') as scope: sess = tf.Session() train_rnn2 = RNN(train_config) scope.reuse_variables() test_rnn2 = RNN(test_config) # tf.initialize_all_variables() no long valid from # 2017-03-02 if using tensorflow >= 0.12 if int((tf.__version__).split('.')[1]) < 12and int((tf.__version__).split('.')[0]) < 1: init = tf.initialize_all_variables() else: init = tf.global_variables_initializer() sess.run(init)