Tensorflow dataset batching for complex data I tried to follow the example in this link:

https://www.tensorflow.org/programmers_guide/datasets

but I am totally lost about how to run the session. I understand the first argument is the operations to run, and feed_dict is the placeholders (my understanding is the batches of the training or test dataset), 

So, here is my code:

batch_size = 100
handle_mix = tf.placeholder(tf.float64, shape=[])
handle_src0 = tf.placeholder(tf.float64, shape=[])
handle_src1 = tf.placeholder(tf.float64, shape=[])
handle_src2 = tf.placeholder(tf.float64, shape=[])
handle_src3 = tf.placeholder(tf.float64, shape=[])


I create the dataset from mp4 tracks and stems, reading mixture and sources magnitudes, and pad them to be suitable to batching

dataset = tf.data.Dataset.from_tensor_slices(
    {"x_mixed":padded_lbl, "y_src0": padded_src[0], "y_src1":   padded_src[1],"y_src2": padded_src[1], "y_src3": padded_src[1]})

dataset = dataset.shuffle(1000).repeat().batch(batch_size)

iterator = tf.data.Iterator.from_structure(dataset.output_types, dataset.output_shapes)


from the example I should do:

next_element = iterator.get_next()

training_init_op = iterator.make_initializer(dataset)
for _ in range(20):
    # Initialize an iterator over the training dataset.
    sess.run(training_init_op)
    for _ in range(100):
        sess.run(next_element)


However, I have a loss, summaries, and optimiser operations and need to feed the data as batches, following another example as:

l, _, summary = sess.run([loss_fn, optimizer, summary_op], feed_dict={handle_mix: batch_mix, handle_src0: batch_src0,
                             handle_src1: batch_src1, handle_src2: batch_src2, handle_src3: batch_src3})


So I thought something like:

batch_mix, batch_src0, batch_src1, batch_src2, batch_src3 = data.train.next_batch(batch_size)


or maybe a separate run to fetch the batches first, then run the optimisation as above, such as:

batch_mix, batch_src0, batch_src1, batch_src2, batch_src3 = sess.run(next_element)
l, _, summary = sess.run([loss_fn, optimizer, summary_op], feed_dict={handle_mix: batch_mix, handle_src0: batch_src0, handle_src1: batch_src1, handle_src2: batch_src2, handle_src3: batch_src3})


This last attempt, returned string names of the batches as created in the tf.data.Dataset.from_tensor_slices ("x_mixed", "y_src0", ... etc) and failed to cast to tf.float64 placeholders in the session.

Can you please let me know how to create this dataset, there might be an error in the structure from tensor slices in the first place, then how to batch them, 

thank you very much, 

Manal
From what I can understand from your code, it seems like you need to use the initializable iterator. Here is why:


Your are creating a dataset from a placeholder.


Here is my solution:

batch_size = 100
handle_mix = tf.placeholder(tf.float64, shape=[])
handle_src0 = tf.placeholder(tf.float64, shape=[])
handle_src1 = tf.placeholder(tf.float64, shape=[])
handle_src2 = tf.placeholder(tf.float64, shape=[])
handle_src3 = tf.placeholder(tf.float64, shape=[])


PASS A TUPLE TO  .from_tensor_slices method of the tf.data.Dataset class

dataset = tf.data.Dataset.from_tensor_slices((handle_mix, handle_src0,
                                               handle_src1, handle_src2,
                                               handle_src3))

dataset = dataset.shuffle(1000).repeat().batch(batch_size)

iter = dataset.make_initializable_iterator()

# unpack five values since dataset was created from five placeholders    
a, b, c, d, e = iter.get_next()


create a session object and initialize the iter making sure to pass "your data" to the placeholders. 'your data' can be numpy arrays

sess = tf.Session()
sess.run(iter.initializer, feed_dict={handle_mix:'your data',
         handle_src0:'your data',handle_src1:'your data',
         handle_src2:'your data',handle_src3:'your data'})


run the following to print the contents from the iterator

print "%r, %r, %r, %r, %r" % sess.run([a,b,c,d,e])


relevant details or clarification are available from the official TensorFlow documentation on how to use the dataset API.