2017-02-12 45 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是靜態的。我使用