user785099
user785099

Reputation: 5553

with respect to the usage of tf.summary.scalar

I am studying a Tensorflow implementation, which includes the following code segment. I am not quite understand what does tf.summary.scalar try to achieve. My understanding is that "queue/%s/fraction_of_%d_full" % (q.name + "_" + phase, capacity) should be a name, but what does this name look like? math_ops.cast(q.size(), tf.float32) * (1. / capacity) should be a tensor, but what does this tensor represent?

capacity = 50
q = tf.FIFOQueue(capacity=50, dtypes=dtypes, shapes=shapes)
tf.summary.scalar("queue/%s/fraction_of_%d_full" %
                  (q.name + "_" + phase, capacity),
                  math_ops.cast(q.size(), tf.float32) * (1. / capacity))

Upvotes: 2

Views: 1350

Answers (1)

Maxim
Maxim

Reputation: 53758

This tf.summary.scalar call will output the queue size (relative to the capacity) to the tensorboard, as it changes during the session.

The scalar will be visible by the name matching this pattern: 'queue/%s/fraction_of_%d_full', e.g. 'queue/fifo_queue_training/fraction_of_100_full', where fifo_queue is the current queue and its capacity is 100.

Its value will be equal to the used up space in the queue, i.e. queue.size() / queue.capacity. This line is just a fancy way to cast it to 32-bit float:

math_ops.cast(q.size(), tf.float32) * (1. / capacity)

Upvotes: 2

Related Questions