Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 使用切片\u输入\u生产者创建的队列为空_Tensorflow - Fatal编程技术网

Tensorflow 使用切片\u输入\u生产者创建的队列为空

Tensorflow 使用切片\u输入\u生产者创建的队列为空,tensorflow,Tensorflow,我有以下代码: import tensorflow as tf xs = tf.random_normal([5, 2]) ys = xs[:, 0] + xs[:, 1] + tf.random_normal([5], stddev=0.01) xs_inp, ys_inp = tf.train.slice_input_producer([xs, ys], num_epochs=20) coord = tf.train.Coordinator() with tf.Session() a

我有以下代码:

import tensorflow as tf

xs = tf.random_normal([5, 2])
ys = xs[:, 0] + xs[:, 1] + tf.random_normal([5], stddev=0.01)

xs_inp, ys_inp = tf.train.slice_input_producer([xs, ys], num_epochs=20)

coord = tf.train.Coordinator()

with tf.Session() as sess:
    threads = tf.train.start_queue_runners(coord=coord)
    for i in range(100):
        print(sess.run([xs_inp, ys_inp]))

    coord.request_stop()
    coord.join(threads)
在我看来,我应该拿100对打印出来,但程序什么都不打印,并抛出异常

tensorflow.python.framework.errors_impl.OutOfRangeError: FIFOQueue '_0_input_producer/input_producer' is closed and has insufficient elements (requested 1, current size 0)

这是一个棘手的难题:在启动队列运行程序之前,您需要添加
sess.run(tf.local\u variables\u initializer())

import tensorflow as tf

xs = tf.random_normal([5, 2])
ys = xs[:, 0] + xs[:, 1] + tf.random_normal([5], stddev=0.01)

xs_inp, ys_inp = tf.train.slice_input_producer((xs, ys), num_epochs=20)

coord = tf.train.Coordinator()

with tf.Session() as sess:
    sess.run(tf.local_variables_initializer())
    threads = tf.train.start_queue_runners(coord=coord)
    for i in range(100):
        print(sess.run([xs_inp, ys_inp]))

    coord.request_stop()
    coord.join(threads)

为什么这是必要的?设置
num_epochs=20
时,TensorFlow隐式创建一个“局部变量”,作为当前历元索引的计数器;当此计数器达到20时,队列将关闭。与所有其他TensorFlow变量一样,必须初始化此计数器。如果不进行初始化,队列运行程序似乎会立即引发错误(遗憾的是,不会打印错误)并关闭队列。。。给出您看到的错误。

这是一个棘手的难题:在启动队列运行程序之前,您需要添加
sess.run(tf.local\u variables\u initializer())

import tensorflow as tf

xs = tf.random_normal([5, 2])
ys = xs[:, 0] + xs[:, 1] + tf.random_normal([5], stddev=0.01)

xs_inp, ys_inp = tf.train.slice_input_producer((xs, ys), num_epochs=20)

coord = tf.train.Coordinator()

with tf.Session() as sess:
    sess.run(tf.local_variables_initializer())
    threads = tf.train.start_queue_runners(coord=coord)
    for i in range(100):
        print(sess.run([xs_inp, ys_inp]))

    coord.request_stop()
    coord.join(threads)

为什么这是必要的?设置
num_epochs=20
时,TensorFlow隐式创建一个“局部变量”,作为当前历元索引的计数器;当此计数器达到20时,队列将关闭。与所有其他TensorFlow变量一样,必须初始化此计数器。如果不进行初始化,队列运行程序似乎会立即引发错误(遗憾的是,不会打印错误)并关闭队列。。。给出您看到的错误。

非常感谢,您帮了我很大的忙。如果没有你,我会花上几天的时间来找出问题所在。非常感谢你,你帮了我大忙。如果没有你,我会花上几天的时间来找出问题所在。