2017-02-12 115 views
0

我正在使用tfrecord来处理序列数据集。当一个例子融入内存时,我会得到两个上下文特征和一个序列特征。上下文特征是序列的长度和序列的标签。序列特征是具有代表每个时间步的特征的字节列表。 所以,我对于每例如三个张量:函数使用张量流的tf.slice_input_producer错误

length TensorShape([]) 
label TensorShape([]) 
frames TensorShape([Dimension(None)]) 

我想用每一个序列的特征来预测标签,所以我必须使标签相同长度的帧。

length=tf.expand_dims(length, 0, name='expand_length') 
label=tf.expand_dims(label, 0, name='expand_label') 
labels=tf.tile(label, length, name='multi_label') 

这一次我得到以下资源:

labels TensorShape([Dimension(None)]) 
frames TensorShape([Dimension(None)]) 

而且我对他们推到一个队列,这样我可以得到一个单帧和标签。

frame, label=tf.train.slice_input_producer([frames, labels]) 

蚂蚁然后批他们然后做网络训练程序。

frames, labels = tf.train.shuffle_batch([frame, label], 4, 16, 8) 

它应该工作,但是,在功能tf.train.slice_input_producer发生错误这里的错误信息:

W d:\build\tensorflow\tensorflow_gpu-r0.12\tensorflow\core\framework\op_kernel.cc:975] Invalid argument: indices = 119 is not in [0, 117) 
     [[Node: slice_timestep/Gather = Gather[Tindices=DT_INT32, Tparams=DT_STRING, validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](parse_one_ex/parse_one_ex:2, slice_timestep/fraction_of_32_full_Dequeue)]] 
W d:\build\tensorflow\tensorflow_gpu-r0.12\tensorflow\core\framework\op_kernel.cc:975] Invalid argument: indices = 119 is not in [0, 117) 
     [[Node: slice_timestep/Gather = Gather[Tindices=DT_INT32, Tparams=DT_STRING, validate_indices=true, _device="/job:localhost/replica:0/task:0/cpu:0"](parse_one_ex/parse_one_ex:2, slice_timestep/fraction_of_32_full_Dequeue)]] 
I d:\build\tensorflow\tensorflow_gpu-r0.12\tensorflow\stream_executor\dso_loader.cc:128] successfully opened CUDA library cupti64_80.dll locally 
W d:\build\tensorflow\tensorflow_gpu-r0.12\tensorflow\core\framework\op_kernel.cc:975] Out of range: RandomShuffleQueue '_3_batch_ex/random_shuffle_queue' is closed and has insufficient elements (requested 4, current size 0) 
     [[Node: batch_ex = QueueDequeueMany[_class=["loc:@batch_ex/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](batch_ex/random_shuffle_queue, batch_ex/n)]] 
W d:\build\tensorflow\tensorflow_gpu-r0.12\tensorflow\core\framework\op_kernel.cc:975] Out of range: RandomShuffleQueue '_3_batch_ex/random_shuffle_queue' is closed and has insufficient elements (requested 4, current size 0) 
     [[Node: batch_ex = QueueDequeueMany[_class=["loc:@batch_ex/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](batch_ex/random_shuffle_queue, batch_ex/n)]] 
W d:\build\tensorflow\tensorflow_gpu-r0.12\tensorflow\core\framework\op_kernel.cc:975] Out of range: RandomShuffleQueue '_3_batch_ex/random_shuffle_queue' is closed and has insufficient elements (requested 4, current size 0) 
     [[Node: batch_ex = QueueDequeueMany[_class=["loc:@batch_ex/random_shuffle_queue"], component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](batch_ex/random_shuffle_queue, batch_ex/n)]] 

的slice_input_producer的名字是slice_timestep

的shuffle_batch的名字is batch_ex

这张图显示在我的张量板上。

the whole graph

local zoomed graph

下面是简单的代码重现错误:

import tensorflow as tf 

context_features = { 
    "length": tf.FixedLenFeature([], dtype=tf.int64), 
    "label": tf.FixedLenFeature([], dtype=tf.int64) 
} 
sequence_features = { 
    "imgs_list": tf.FixedLenSequenceFeature([], dtype=tf.string), 
} 


file=tf.train.string_input_producer(['./train.tfrecord']) 
reader=tf.TFRecordReader() 
_, ex=reader.read(file) 

context_parsed, sequence_parsed = tf.parse_single_sequence_example(
    serialized=ex, 
    context_features=context_features, 
    sequence_features=sequence_features 
) 
length=tf.cast(context_parsed['length'], tf.int32) 
label=tf.cast(context_parsed['label'], tf.int32) 
length=tf.expand_dims(length, 0, name='expand_length') 
label=tf.expand_dims(label, 0, name='expand_label') 
label=tf.tile(label, length) 
imcontent, label=tf.train.slice_input_producer([sequence_parsed['imgs_list'], label]) 
im=tf.image.decode_jpeg(imcontent, 3) 
im=tf.image.resize_images(im, [224, 224]) 
im, label = tf.train.shuffle_batch([im, label], 4, 16, 8, name='batch_ex') 
with tf.Session() as sess: 
    tf.train.start_queue_runners(sess) 
    fig=plt.figure() 
    while(True): 
     [res, res2]=sess.run([im, label]) 
     print(res2) 
+0

您的错误状态'_3_batch_ex/random_shuffle_queue已关闭,并且元素不足(请求4,当前大小为0)'根据我的经验,这通常只是表示无法从输入文件中读取任何内容。你确定它找到了正确的东西,那里有足够的东西吗?它说它试图读取一组4条记录并得到零... –

+0

谢谢你的帮助。我解决了。 – mxmxlwlw

回答

0

我已经解决了。看来slice_input_producer是静态的。我使用