tensorflow网站上:
tf.train.slice_input_producer(tensor_list, num_epochs=None, shuffle=True, seed=None, capacity=32, shared_name=None, name=None)
See the guide: Inputs and Readers > Input pipeline
Produces a slice of each Tensor
in tensor_list
.
Implemented using a Queue -- a QueueRunner
for the Queueis added to the current Graph
's QUEUE_RUNNER
collection.
Args:
tensor_list
: A list ofTensor
objects. EveryTensor
intensor_list
must have the same size in the first dimension.num_epochs
: An integer (optional). If specified,slice_input_producer
produces each slicenum_epochs
times before generating anOutOfRange
error. If not specified,slice_input_producer
can cycle through the slices an unlimited number of times.shuffle
: Boolean. If true, the integers are randomly shuffled within each epoch.seed
: An integer (optional). Seed used if shuffle == True.capacity
: An integer. Sets the queue capacity.shared_name
: (optional). If set, this queue will be shared under the given name across multiple sessions.name
: A name for the operations (optional).
Returns:
A list of tensors, one for each element of tensor_list
. If the tensor in tensor_list
has shape [N, a, b, .., z]
, then the corresponding output tensor will have shape [a, b, ..., z]
.
Raises:
ValueError
: ifslice_input_producer
produces nothing fromtensor_list1.
import tensorflow as tf images = ['wgb1', 'wgb2', 'wgb3'] labels= [1,2,3] f = tf.train.slice_input_producer([images, labels],batch_size=batch_size,num_threads = 4, shuffle=True) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(sess=sess, coord=coord) k = sess.run(f) print('k', k) coord.request_stop() coord.join(threads)
输出结果
k [b'wgb2', 2] 其中b指得是byte 说明:Python 3.x版本中,把'xxx'
和u'xxx'
统一成Unicode编码,即写不写前缀u
都是一样的,而以字节形式表示的字符串则必须加上b
前缀:b'xxx'
。 http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386819196283586a37629844456ca7e5a7faa9b94ee8000 3. 我开始写的时候,一直停留在run中,开始的程序为:
import tensorflow as tf images = ['wgb1', 'wgb2', 'wgb3'] labels= [1,2,3] f = tf.train.slice_input_producer([images, labels],batch_size=batch_size,num_threads = 4, shuffle=True) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) k = sess.run(f) print('k', k)
错误原因:
因为队列是空的,出现了无限等待的缘故,需要启动QueueRunner来填充队列