如何在可初始化的\u i上使用共享的\u名称

2024-09-28 23:51:49 发布

您现在位置:Python中文网/ 问答频道 /正文

在分布式tensorflow中,我需要在一个worker上处理输入数据,并在另一个不同的会话上使用它们。 “make_initializable_iterator”有一个未记录的参数“shared_name”,但是如果不在每个会话上创建数据集,如何初始化迭代器呢。你知道吗

def make_initializable_iterator(self, shared_name=None):
    """Creates an `Iterator` for enumerating the elements of this dataset.
    Note: The returned iterator will be in an uninitialized state,
    and you must run the `iterator.initializer` operation before using it"""

更清楚的是,如果我定义了一个具有共享名称的迭代器,那么如何在另一个会话中使用这个迭代器。你知道吗


Tags: the数据nameselfan参数maketensorflow
1条回答
网友
1楼 · 发布于 2024-09-28 23:51:49

iter_init_op可能就是您要搜索的内容:

# 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

在会议期间:

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

相关问题 更多 >