我使用tensorboard
来监控我的训练过程,情节非常好,但有一些情节令我感到困惑。
首先Using_Queues_Lib.py
:(使用队列和多线程读取二进制数据,参考cifar 10 example)
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
from six.moves import xrange # pylint: disable=redefined-builtin
import tensorflow as tf
NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 50000
REAL32_BYTES=4
def read_dataset(filename_queue,data_length,label_length):
class Record(object):
pass
result = Record()
result_data = data_length*REAL32_BYTES
result_label = label_length*REAL32_BYTES
record_bytes = result_data + result_label
reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
result.key, value = reader.read(filename_queue)
record_bytes = tf.decode_raw(value, tf.float32)
result.data = tf.strided_slice(record_bytes, [0],[data_length])#record_bytes: tf.float list
result.label = tf.strided_slice(record_bytes, [data_length],[data_length+label_length])
return result
def _generate_data_and_label_batch(data, label, min_queue_examples,batch_size, shuffle):
num_preprocess_threads = 16 #only speed code
if shuffle:
data_batch, label_batch = tf.train.shuffle_batch([data, label],batch_size=batch_size,num_threads=num_preprocess_threads,capacity=min_queue_examples + batch_size,min_after_dequeue=min_queue_examples)
else:
data_batch, label_batch = tf.train.batch([data, label],batch_size=batch_size,num_threads=num_preprocess_threads,capacity=min_queue_examples + batch_size)
return data_batch, label_batch
def inputs(data_dir, batch_size,data_length,label_length):
filenames = [os.path.join(data_dir, 'test_data_SE.dat')]
for f in filenames:
if not tf.gfile.Exists(f):
raise ValueError('Failed to find file: ' + f)
filename_queue = tf.train.string_input_producer(filenames)
read_input = read_dataset(filename_queue,data_length,label_length)
read_input.data.set_shape([data_length]) #important
read_input.label.set_shape([label_length]) #important
min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
min_fraction_of_examples_in_queue)
print ('Filling queue with %d samples before starting to train. '
'This will take a few minutes.' % min_queue_examples)
return _generate_data_and_label_batch(read_input.data, read_input.label,
min_queue_examples, batch_size,
shuffle=True)
在主要功能中,我写道:
data_train,labels_train=Using_Queues_Lib.inputs(
filenames=r'./training.dat',
batch_size=32,
data_length=2,
label_length=1,
name='Training')
data_validate,labels_validate=Using_Queues_Lib.inputs(
filenames=r'./validating.dat',
batch_size=32*30,
data_length=2,
label_length=1,
name='Validating')
摘要部分是:
with tf.name_scope('loss'):
loss = tf.reduce_mean(tf.square(y_ - y))
loss_summary=tf.summary.scalar('loss', loss)
with tf.name_scope('train'):
global_step=tf.Variable(0,trainable=False)
learning_rate=...
tf.summary.scalar('learning_rate', learning_rate)
train_step =tf.train.GradientDescentOptimizer(learning_rate).minimize(loss,global_step=global_step)
sess=tf.InteractiveSession(config=config)
summary_op = tf.summary.merge_all()
summaries_dir = './logs'
train_writer = tf.summary.FileWriter(summaries_dir + '/train', sess.graph)
validate_writer = tf.summary.FileWriter(summaries_dir + '/validate')
tf.global_variables_initializer().run()
tf.train.start_queue_runners()
for epoch in xrange(TRAINING_EPOCHS):
BatchNum_Per_Epoch=TRAINING_DATA_SAMPLES_LENGTH/BATCH_SIZE
for i in xrange(BatchNum_Per_Epoch):
data_batch,label_batch=sess.run([data_train,labels_train])
summary, _=sess.run([summary_op,train_step], feed_dict={x: data_batch, y_: label_batch})
train_writer.add_summary(summary, sess.run(global_step))
data_batch_validate,label_batch_validate=
sess.run([data_validate,labels_validate])
summary, loss_value_validate=sess.run([loss_summary,loss],
feed_dict={x: data_batch_validate, y_: label_batch_validate})
validate_writer.add_summary(summary, sess.run(global_step))
在张量板中,我看到了这一点,但我不知道这意味着什么。
答案 0 :(得分:2)
您没有发布显示摘要部分的源代码,但是从图中我认为您在每个汇总步骤中绘制num_elements_in_the_queue/capacity_of_the_queue
的分数(浅色垂直线是数据点,而较暗的橙色是平滑的平均值。