问题
I use tensorboard
to monitor my training process and the plot are so good, but there are some plots that confuse me.
First Using_Queues_Lib.py
:(it Using Queues and MultiThreads to read binary data,reference 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)
In the main function, I write:
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')
And the summary part is:
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))
In the tensorboard I see this but I don't know what it means.
First:
Second:
回答1:
You didn’t post the source code that shows the summary part, but from the graph I think you are plotting the fraction of num_elements_in_the_queue/capacity_of_the_queue
at each summary step (the light color vertical lines are the data points, while the darker orange color is the smoothed average).
来源:https://stackoverflow.com/questions/43411528/what-the-meaning-of-the-plot-of-tensorboard-when-using-queues