我看着the interactive demo in tensorflow,似乎他们有单独的测试和训练图,可以切换。例如,他们对测试和训练有不同的准确度:
可以在它们之间切换:
他们甚至也有单独的百分位(hist)图表:
什么是提供这种有用功能的TensorFlow代码?
我尝试过测试和火车错误,但我没有得到这样的情节。这就是我试过的:
with open(path+errors_pretty, 'w+') as f_err_msgs:
with tf.Session() as sess:
merged = tf.merge_all_summaries()
writer = tf.train.SummaryWriter(tensorboard_data_dump, sess.graph)
sess.run( tf.initialize_all_variables() )
for i in xrange(steps):
## Create fake data for y = W.x + b where W = 2, b = 0
#(batch_xs, batch_ys) = get_batch_feed(X_train, Y_train, M, phase_train)
feed_dict_batch = get_batch_feed(X_train, Y_train, M, phase_train)
## Train
if i%report_error_freq == 0:
(summary_str_train,train_error) = sess.run(fetches=[merged, l2_loss], feed_dict=feed_dict_train)
(summary_str_test,test_error) = sess.run(fetches=[merged, l2_loss], feed_dict=feed_dict_test)
writer.add_summary(summary_str_train, i)
loss_msg = "Model *%s%s*, step %d/%d, training error %g, test error %g \n"%(model,nb_hidden_layers,i,steps,train_error,test_error)
mdl_info_msg = "Opt: %s, BN %s, After %d/%d iteration, Init: %s \n" % (optimization_alg,bn,i,steps,init_type)
print_messages(loss_msg, mdl_info_msg)
# store results
results['train_errors'].append(train_error)
results['test_errors'].append(test_error)
# write errors to pretty print
f_err_msgs.write(loss_msg)
f_err_msgs.write(mdl_info_msg)
# save mdl
#save_path = saver.save(sess, path+'/tmp_mdls/model.ckpt',global_step=i)
if mdl_save:
save_path = saver.save(sess, path+mdl_dir+'/model.ckpt',global_step=i)
sess.run(fetches=[merged,train_step], feed_dict=feed_dict_batch)
#sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
答案 0 :(得分:4)
Tensor board利用日志文件夹结构,组织前端。要获得两个单独的准确度,在两个文件夹中有两个单独的摘要编写器,如下所示
with open(path+errors_pretty, 'w+') as f_err_msgs:
with tf.Session() as sess:
merged = tf.merge_all_summaries()
***train_writer = tf.train.SummaryWriter(tensorboard_train_data_dump, sess.graph)***
***test_writer = tf.train.SummaryWriter(tensboar_test_data_sump, sess.graph)***
sess.run( tf.initialize_all_variables() )
for i in xrange(steps):
## Create fake data for y = W.x + b where W = 2, b = 0
#(batch_xs, batch_ys) = get_batch_feed(X_train, Y_train, M, phase_train)
feed_dict_batch = get_batch_feed(X_train, Y_train, M, phase_train)
## Train
if i%report_error_freq == 0:
(summary_str_train,train_error) = sess.run(fetches=[merged, l2_loss], feed_dict=feed_dict_train)
(summary_str_test,test_error) = sess.run(fetches=[merged, l2_loss], feed_dict=feed_dict_test)
***train_writer.add_summary(summary_str_train, i)
test_writer.add_summary(summary_str_test, i)***
loss_msg = "Model *%s%s*, step %d/%d, training error %g, test error %g \n"%(model,nb_hidden_layers,i,steps,train_error,test_error)
mdl_info_msg = "Opt: %s, BN %s, After %d/%d iteration, Init: %s \n" % (optimization_alg,bn,i,steps,init_type)
print_messages(loss_msg, mdl_info_msg)
# store results
results['train_errors'].append(train_error)
results['test_errors'].append(test_error)
# write errors to pretty print
f_err_msgs.write(loss_msg)
f_err_msgs.write(mdl_info_msg)
# save mdl
#save_path = saver.save(sess, path+'/tmp_mdls/model.ckpt',global_step=i)
if mdl_save:
save_path = saver.save(sess, path+mdl_dir+'/model.ckpt',global_step=i)
sess.run(fetches=[merged,train_step], feed_dict=feed_dict_batch)
#sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
虽然这有点乱,但这是一个可以让你2"运行"的解决方法。我已经自己完成了这一点,如下图所示。紫色线对应于不同时期的训练精度,并且棕色线对应于不同时期的验证准确度。希望这可以帮助你:)