I am changing my TensorFlow code from the old queue interface to the new Dataset API . In my old codec, I tracked the era score, while increasing tf.Variable every time a new input tensor gets access and is processed in the queue. I would like this epoch counter with the new Dataset API, but I am having problems with its operation.
Since I create a variable number of data elements at the pre-processing stage, this is not just a question of increasing the counter (Python) in the training cycle - I need to calculate the epoch counter with respect to entering queues or a data set.
I emulated what I had before with the old queue system, and here is what I got for the Dataset API (simplified example):
with tf.Graph().as_default(): data = tf.ones(shape=(10, 512), dtype=tf.float32, name="data") input_tensors = (data,) epoch_counter = tf.Variable(initial_value=0.0, dtype=tf.float32, trainable=False) def pre_processing_func(data_): data_size = tf.constant(0.1, dtype=tf.float32) epoch_counter_op = tf.assign_add(epoch_counter, data_size) with tf.control_dependencies([epoch_counter_op]):
However, this does not work. It crashes with a cryptic error message:
TypeError: In op 'AssignAdd', input types ([tf.float32, tf.float32]) are not compatible with expected types ([tf.float32_ref, tf.float32])
A closer check reveals that the epoch_counter variable epoch_counter not be available in pre_processing_func at all. Can he live on a different schedule?
Any idea how to fix the above example? Or how to get an era counter (with decimal points, for example 0.4 or 2.9), using some other means?