2017-02-12 3 views
0

Я использую tfrecord для обработки набора данных последовательностей. Когда один пример считывается в память, я получу две функции контекста и одну функцию последовательности. Контекстные функции - это длина последовательностей и метка последовательностей. Функция последовательности - это список байтов, представляющих функцию каждого временного шага. Поэтому у меня есть три тензора для каждого примера:function tf.slice_input_producer error using tensorflow

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

Ваши ошибки state '_3_batch_ex/random_shuffle_queue закрыты и не имеют достаточного количества элементов (запрошено 4, текущий размер 0)' По моему опыту это обычно является признаком того, что он ничего не может прочитать из вашего входного файла. Вы уверены, что это правильно, и там достаточно материала? В нем говорится, что он пытается прочитать набор из 4 записей и получить нуль ... –

+0

Благодарим за помощь. Я решил. – mxmxlwlw

ответ

0

Я решил. Кажется, что slice_input_producer статичен. Я использую