启动采集器,将运行session环境内的参数都保存到文件里,后续就可以用
with tf.Session() as sess: sess.run(tf.global_variables_initializer()) file_writer = tf.summary.FileWriter('./logs/1', sess.graph)
后续通过TensorBoard打开这个文件,查看这个session的模型,运行
tensorboard --logdir=./logs/1
打开浏览器,通常是通过本机的6006端口访问
在session中,对模型做归类
with tf.name_scope("RNN_layers"): lstm = tf.contrib.rnn.BasicLSTMCell(lstm_size) drop = tf.contrib.rnn.DropoutWrapper(lstm, output_keep_prob=keep_prob) cell = tf.contrib.rnn.MultiRNNCell([drop] * num_layers)with tf.name_scope("RNN_layers")
查看session文件效果如图
with tf.name_scope('logits'): softmax_w = tf.Variable(tf.truncated_normal((lstm_size, num_classes), stddev=0.1), name='softmax_w') softmax_b = tf.Variable(tf.zeros(num_classes), name='softmax_b') logits = tf.matmul(output, softmax_w) + softmax_b tf.summary.histogram('softmax_w', softmax_w) tf.summary.histogram('softmax_b', softmax_b) #以直方图采集权重 ....merged = tf.summary.merge_all() #收集全部采集点.....with tf.Session() as sess: sess.run(tf.global_variables_initializer()) train_writer = tf.summary.FileWriter('./logs/2/train', sess.graph) .... summary, batch_loss, new_state, _ = sess.run([model.merged, model.cost, model.final_state, model.optimizer], feed_dict=feed) #运行采集点的收集器merge .... train_writer.add_summary(summary, iteration) #采集到的信息写入文件
epochs = 20batch_size = 100num_steps = 100train_x, train_y, val_x, val_y = split_data(chars, batch_size, num_steps)for lstm_size in [128,256,512]: for num_layers in [1, 2]: for learning_rate in [0.002, 0.001]: log_string = 'logs/4/lr={},rl={},ru={}'.format(learning_rate, num_layers, lstm_size) #每一对参数写入一个文件 writer = tf.summary.FileWriter(log_string) model = build_rnn(len(vocab), batch_size=batch_size, num_steps=num_steps, learning_rate=learning_rate, lstm_size=lstm_size, num_layers=num_layers) train(model, epochs, writer)#每个文件用采集器收集信息
对每个参数配置做记录,最终可以得到他们之间对比的图案
withtf.name_scope('logits'):
tf.summary.histogram('softmax_w',softmax_w)
merged=tf.summary.merge_all()
train_writer=tf.summary.FileWriter('./logs/2/train',sess.graph)