使用队列时张量板图的含义是什么? [英] What the meaning of the plot of tensorboard when using Queues?

查看:22
本文介绍了使用队列时张量板图的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 tensorboard 来监控我的训练过程,情节非常好,但有一些情节让我感到困惑.

首先Using_Queues_Lib.py:(它使用队列和多线程读取二进制数据,参考

第二:

解决方案

您没有发布显示摘要部分的源代码,但从图中我认为您正在绘制 num_elements_in_the_queue/capacity_of_the_queue 在每个汇总步骤(浅色垂直线是数据点,而深橙色是平滑平均值).

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:

解决方案

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).

这篇关于使用队列时张量板图的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆