首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TensorFlow:如何在string_input_producer中使用“num_epochs”

TensorFlow:如何在string_input_producer中使用“num_epochs”
EN

Stack Overflow用户
提问于 2017-09-06 09:47:51
回答 1查看 969关注 0票数 0

如果没有一个string_input_producer错误(请求x,当前大小为0),我无法在OutOfRange上启用时间限制。我请求多少元素似乎并不重要,总是有0可用。

下面是我的FileQueue构建器:

代码语言:javascript
复制
def get_queue(base_directory):
    files = [f for f in os.listdir(base_directory) if f.endswith('.bin')]
    shuffle(files)
    file = [os.path.join(base_directory, files[0])]
    fileQueue = tf.train.string_input_producer(file, shuffle=False, num_epochs=1)

    return fileQueue

如果我从num_epochs=1中删除string_input_producer,它可以很好地创建示例。

我的输入管道:

代码语言:javascript
复制
def input_pipeline(instructions, fileQueue):
    example, label, feature_name_list = read_binary_format(fileQueue, instructions)

    num_preprocess_threads = 16
    capacity = 20

    example, label = tf.train.batch(
        [example, label],
        batch_size=50000,    # set the batch size way bigger so we always return the full amount of samples from the file
        allow_smaller_final_batch=True,
        capacity=capacity,
        num_threads=num_preprocess_threads)

    return example, label

最后是我的会议:

代码语言:javascript
复制
with tf.Session(graph=tf.Graph()) as sess:
    train_inst_set = sf.DeserializationInstructions.from_filename(os.path.join(input_dir, "Train/config.json"))
    fileQueue = sf.get_queue(os.path.join(input_dir, "Train"))
    features_train, labels_train = sf.input_pipeline(train_inst_set, fileQueue)
    sess.run(tf.global_variables_initializer())

    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord, sess=sess)

    train_feature_batch, train_label_batch = sess.run([features_train, labels_train])
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-06 23:07:24

这个问题是由以下原因引起的:第1045期

无论出于什么原因,tf.global_variable_initialiser并不会初始化所有变量。您也需要初始化局部变量。

添加

代码语言:javascript
复制
sess.run(tf.group(tf.global_variables_initializer(), tf.local_variables_initializer()))

敬你的会议。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46071998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档