TFRecordReader in data input pipeline
<p>I'm currently stuck with an implementation problem of <code>TFRecordReader</code></p>

<p>This is the setup : </p>

<pre><code>trainQ = tf.train.string_input_producer(fileList)
RecReader = tf.TFRecordReader()
batch_strings = RecReader.read(trainQ)
con,seq=tf.parse_single_sequence_example(batch_strings.value,context_features=lengths_context,sequence_features=convo_pair,name='parse_ex')
encoder_inputs,decoder_inputs,enc_len,dec_len = seq['utterance'],seq['response'],con['utter_length'],con['resp_length']
mini_batch = tf.train.batch([encoder_inputs,decoder_inputs,enc_len,dec_len,decoder_inputs],batch_size,2,capacity=50*batch_size,dynamic_pad = True,enqueue_many=False)
encoder_inp,decoder_inp,encoder_lens,decoder_lens,labels = mini_batch
...
&lt;build rest of the model&gt;
...
loss = &lt;some loss&gt;
train_ops = &lt;optimizer&gt;.minimize(loss)
</code></pre>

<p>Now when I do <code>train_ops.run()</code>, it automatically reads off the queue and trains the model over a batch. But if I want to evaluate some intermediate variable, I cannot do <code>variable.eval()</code> since that would mean a new batch being read off the trainQ queue with different values </p>

<p>One way I can think of circumventing this to use a placeholder to feed <code>parse_single_example</code> and populating the placeholder in the train loop each time. But is there a better way of doing this i.e. evaluating variables without reading off the queue again?</p>

<p>Hope this is not confusing</p>

<p>If you want to evaluate an intermediate layer (call it <code>conv3</code>) that depends on the batch input every 100 iterations, you can do the following:</p>

<pre class="lang-py prettyprint-override"><code>for step in range(100000):
    if step % 100 != 0:
        # only run the training operation
        sess.run(train_op)
    else:
        # run train_op AND `conv3` at the same time
        _, conv3_value = sess.run([train_op, conv3])
</code></pre>

<p>The trick here is to call <code>train_op</code> and <code>conv3</code> in the same call the <code>tf.Session</code>. That way, a batch is read off the training queue to train one step, but it is also used at the same time to compute <code>conv3</code>.</p>

python queue tensorflow