Skip to content Skip to sidebar Skip to footer

How To Use Shared_name On Initializable_iterator

In distributed tensorflow, I need processing input datas on one worker and consuming them on other different session. 'make_initializable_iterator' have an undocumented parameter '

Solution 1:

The iter_init_op might be what you are searching for:

# this's how a input pipeline usually looks like
ncores = multiprocessing.cpu_count()
dataset = tf.data.Dataset.from_tensor_slices(file_list))
dataset = dataset.map(augmentation_function, num_parallel_calls=ncores)
batch = dataset.shuffle(batch_size).batch(batch_size).prefetch(5)

# construct iterator
it = batch.make_initializable_iterator(shared_name='shared_iterator')
iter_init_op = it.initializer # you call this operation within session to initialiser

Within the session:

with tf.Session() as sess:
     ...
     for epoch in range(nb_epoch):
          # init iterator during epoch
          sess.run(iter_init_op)

Post a Comment for "How To Use Shared_name On Initializable_iterator"