栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用TensorFlow tf.train.string_input_producer生成几个纪元数据?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用TensorFlow tf.train.string_input_producer生成几个纪元数据?

正如Nicolas观察到的那样,

tf.train.string_input_producer()
API不能让您检测到何时到达时代的尽头。而是将所有纪元串联在一起,组成一个较长的批处理。因此,我们最近(在TensorFlow1.2中)添加了
tf.contrib.data
API,该API使得可以表达更复杂的管道,包括您的用例。

以下代码段显示了如何使用编写程序

tf.contrib.data

import tensorflow as tfdef input_pipeline(filenames, batch_size):    # Define a `tf.contrib.data.Dataset` for iterating over one epoch of the data.    dataset = (tf.contrib.data.TextLineDataset(filenames)    .map(lambda line: tf.depre_csv(         line, record_defaults=[['1'], ['1'], ['1']], field_delim='-'))    .shuffle(buffer_size=10)  # Equivalent to min_after_dequeue=10.    .batch(batch_size))    # Return an *initializable* iterator over the dataset, which will allow us to    # re-initialize it at the beginning of each epoch.    return dataset.make_initializable_iterator()filenames=['1.txt']batch_size = 3num_epochs = 10iterator = input_pipeline(filenames, batch_size)# `a1`, `a2`, and `a3` represent the next element to be retrieved from the iterator.    a1, a2, a3 = iterator.get_next()with tf.Session() as sess:    for _ in range(num_epochs):        # Resets the iterator at the beginning of an epoch.        sess.run(iterator.initializer)        try: while True:     a, b, c = sess.run([a1, a2, a3])     print(a, b, c)        except tf.errors.OutOfRangeError: # This will be raised when you reach the end of an epoch (i.e. the # iterator has no more elements). pass        # Perform any end-of-epoch computation here.        print('Done training, epoch reached')


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/624755.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号