tensorboard可视化图和损失曲线
1、首先定义好loss的计算:
with tf.name_scope('train'):
xentropy = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=y,
logits=logits)
loss = tf.reduce_mean(xentropy,name='loss')
optimizer = tf.train.AdamOptimizer()
training_op = optimizer.minimize(loss)
2、在代码中加入:
mse_summary = tf.summary.scalar('loss',loss)
file_writer = tf.summary.FileWriter('./logs',tf.get_default_graph())
3、最后进行训练:
.....
summary_str = mse_summary.eval(feed_dict={X:X_batch,y:y_batch})
step = i * batch_size + j
j += 1
file_writer.add_summary(summary_str, step)
.....
4、最后进行可视化
%load_ext tensorboard
tensorboard --logdir logs
#这个logs是上面的那个file_writer里面的目录’./logs‘