2015-12-02 3 views
15

sto leggendo serie di immagini da ottenere idea here da tfrecords (convertiti dal this)tensorflow random_shuffle_queue è chiuso e ha elementi sufficienti

Le mie immagini sono immagini cifar, [32, 32, 3] e, come si può vedere durante la lettura e passando le immagini le forme sono normali (batch_size=100)

i 2 problemi più importanti indicati nel registro, per quanto ne so è

  1. Forma di 12228, che non so da dove ottengo questo. Tutti i miei tensori sono sia in forma [32, 32, 3] o [Nessuno, 3072]
  2. corto di campione

Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)

Come posso risolvere questo problema?

Logs:

1- image shape is TensorShape([Dimension(3072)]) 
1.1- images batch shape is TensorShape([Dimension(100), Dimension(3072)]) 
2- images shape is TensorShape([Dimension(100), Dimension(3072)]) 

W tensorflow/core/kernels/queue_ops.cc:79] Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
W tensorflow/core/common_runtime/executor.cc:1027] 0x7fa72abc89a0 Compute status: Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
    [[Node: input/shuffle_batch/random_shuffle_queue_enqueue = QueueEnqueue[Tcomponents=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input/shuffle_batch/random_shuffle_queue, input/sub, input/Cast_1)]] 
W tensorflow/core/kernels/queue_ops.cc:79] Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
W tensorflow/core/common_runtime/executor.cc:1027] 0x7fa72ab9d080 Compute status: Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
    [[Node: input/shuffle_batch/random_shuffle_queue_enqueue = QueueEnqueue[Tcomponents=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input/shuffle_batch/random_shuffle_queue, input/sub, input/Cast_1)]] 
W tensorflow/core/kernels/queue_ops.cc:79] Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
W tensorflow/core/common_runtime/executor.cc:1027] 0x7fa7285e55a0 Compute status: Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
    [[Node: input/shuffle_batch/random_shuffle_queue_enqueue = QueueEnqueue[Tcomponents=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input/shuffle_batch/random_shuffle_queue, input/sub, input/Cast_1)]] 
W tensorflow/core/kernels/queue_ops.cc:79] Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
W tensorflow/core/common_runtime/executor.cc:1027] 0x7fa72aadb080 Compute status: Invalid argument: Shape mismatch in tuple component 0. Expected [3072], got [12288] 
    [[Node: input/shuffle_batch/random_shuffle_queue_enqueue = QueueEnqueue[Tcomponents=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input/shuffle_batch/random_shuffle_queue, input/sub, input/Cast_1)]] 
W tensorflow/core/common_runtime/executor.cc:1027] 0x7fa72ad499a0 Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0) 
    [[Node: input/shuffle_batch = QueueDequeueMany[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input/shuffle_batch/random_shuffle_queue, input/shuffle_batch/n)]] 
Traceback (most recent call last): 
    File "/Users/HANEL/Documents/my_cifar_train.py", line 110, in <module> 
    tf.app.run() 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/default/_app.py", line 11, in run 
    sys.exit(main(sys.argv)) 
    File "/Users/HANEL/my_cifar_train.py", line 107, in main 
    train() 
    File "/Users/HANEL/my_cifar_train.py", line 76, in train 
    _, loss_value = sess.run([train_op, loss]) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 345, in run 
    results = self._do_run(target_list, unique_fetch_targets, feed_dict_string) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 419, in _do_run 
    e.code) 
tensorflow.python.framework.errors.OutOfRangeError: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0) 
    [[Node: input/shuffle_batch = QueueDequeueMany[component_types=[DT_FLOAT, DT_INT32], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input/shuffle_batch/random_shuffle_queue, input/shuffle_batch/n)]] 
Caused by op u'input/shuffle_batch', defined at: 
    File "/Users/HANEL/my_cifar_train.py", line 110, in <module> 
    tf.app.run() 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/default/_app.py", line 11, in run 
    sys.exit(main(sys.argv)) 
    File "/Users/HANEL/my_cifar_train.py", line 107, in main 
    train() 
    File "/Users/HANEL/my_cifar_train.py", line 39, in train 
    images, labels = my_input.inputs() 
    File "/Users/HANEL/my_input.py", line 157, in inputs 
    min_after_dequeue=200) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/training/input.py", line 453, in shuffle_batch 
    return queue.dequeue_many(batch_size, name=name) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/data_flow_ops.py", line 245, in dequeue_many 
    self._queue_ref, n, self._dtypes, name=name) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_data_flow_ops.py", line 319, in _queue_dequeue_many 
    timeout_ms=timeout_ms, name=name) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 633, in apply_op 
    op_def=op_def) 
    File "/Users 
/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1710, in create_op 
    original_op=self._default_original_op, op_def=op_def) 
    File "/Users/HANEL/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 988, in __init__ 
    self._traceback = 

_extract_stack() 
+0

Ciao @mrry Sì, lo invierò a te, ma ho capito il secondo problema, ho usato il training_iterations su 20 che è inferiore a 100 (batch_size) ha causato gli elementi insufficienti. Il primo problema credo sia la dimensione del thread della mia macchina, è 4 thread e 12228 = 4 * 3072 –

+0

Sì @mrry hai ragione, ho aggiunto tutti questi per il debug, image.show/set_shape, ... La versione corrente è lo stesso che hai detto –

+1

Il problema più probabile è che le dimensioni passate a 'set_shape()' non corrispondono alle dimensioni reali dei tensori che vengono prodotti da 'decode_raw' - forse qualcosa è andato storto in precedenza nella pipeline. Per scoprire le forme vere, puoi fare qualcosa come: 'image_shape = tf.shape (image); ...; sess.run (image_shape) 'per ottenere la forma vera. – mrry

risposta

4

Per riassumere i commenti, il

Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0) 

è stato causato dalla coda di rimanere a corto di dati. Questo è spesso causato da pensare di avere dati sufficienti per n iterazioni, quando in realtà hai solo sufficiente per M iterazioni dove M < N.

Un suggerimento per capire la quantità di dati che in realtà hanno è quello di contare quante volte si può leggere i dati prima che un'eccezione OutOfRangeError venga generata dalla coda.

+1

Ho riscontrato un problema simile. Tuttavia, non penso che i miei dati non siano abbastanza. Ho un set di dati di 8000 campioni e ho impostato i num_epoches di filename_queue su 2, quindi dovrebbero essere 16000 campioni da accodare. My batch_size è impostato su 100, quindi dovrebbe iterare 160 volte. Tuttavia, ho ancora avvertimenti del tipo "fuori limite", anche se inserisco il codice di iterazione in un try ... exception block che può catturare l'eccezione OutOfRange. Quindi tutte le possibili ragioni? –

2

Ho avuto esattamente lo stesso problema oggi e più tardi ho scoperto che era il file di dati di input scaricato dal "famoso set di dati" (come https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data) che ha causato l'errore: ha alcune righe vuote alla fine del file . Rimuovere le linee vuote, l'errore era sparito!

+0

Esattamente! Tu salvi la mia giornata! Grazie! Cancellare la riga vuota alla fine del file, problema risolto! – callofdutyops

7

Ho avuto un problema simile. Scavando giro per il web, si è scoperto che se si utilizzano alcuni num_epochs argomento, è necessario inizializzare tutte le variabili local, in modo che il codice dovrebbe finire per assomigliare:

with tf.Session() as sess: 
    sess.run(tf.local_variables_initializer()) 
    sess.run(tf.global_variables_initializer()) 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 

    # do your stuff here 

    coord.request_stop() 
    coord.join(threads) 

Se pubblichi un po 'di codice, forse potrebbe dare un'occhiata più approfondita. Nel frattempo, HTH.

+0

Grazie! 'sess.run (tf.local_variables_initializer())' era esattamente questo! – Temak

+1

Felice di averlo aiutato. Poiché si tratta di un problema abbastanza comune, l'OP potrebbe contrassegnare la risposta come corretta per ulteriori lettori? Grazie. – petrux

5

Probabilmente si sta elaborando l'esempio TFRecord analizzato in modo errato. Per esempio. cercando di rimodellare un tensore a una dimensione incompatibile. È possibile eseguire il debug utilizzando un tf_record_iterator per confermare i dati che state leggendo è memorizzato il modo di pensare che è:

import tensorflow as tf 
import numpy as np 

tfrecords_filename = '/path/to/some.tfrecord' 
record_iterator = tf.python_io.tf_record_iterator(path=tfrecords_filename) 

for string_record in record_iterator: 
    # Parse the next example 
    example = tf.train.Example() 
    example.ParseFromString(string_record) 

    # Get the features you stored (change to match your tfrecord writing code) 
    height = int(example.features.feature['height'] 
           .int64_list 
           .value[0]) 

    width = int(example.features.feature['width'] 
           .int64_list 
           .value[0]) 

    img_string = (example.features.feature['image_raw'] 
            .bytes_list 
            .value[0]) 
    # Convert to a numpy array (change dtype to the datatype you stored) 
    img_1d = np.fromstring(img_string, dtype=np.float32) 
    # Print the image shape; does it match your expectations? 
    print(img_1d.shape) 
+1

Phew, quello era un bug approssimativo, ma la tua risposta l'ha risolto. Ho avuto un nodo 'tf.py_func' che ha restituito il tipo sbagliato, ma TF mostra solo un messaggio di errore fuorviante su elementi insufficienti. –

0

Ho avuto questo stesso problema e nessuna delle risposte precedenti sembrava di risolverlo così sarò anche carillon in.

Per me il problema è stato l'elenco delle funzionalità che stavo passando a parse_single_example. Per qualsiasi motivo (dal momento che sto usando una lista float?) Nel mio file tfrecords ho bisogno di specificare la lunghezza dell'array nel mio elenco di funzionalità o utilizzare tf.VarLenFeature cioè:

feature_structure = {'features': tf.FixedLenFeature([FEATURE_SIZE], tf.float32), 
      'outputs': tf.FixedLenFeature([OUTPUT_SIZE], tf.float32)} 
d_features = tf.parse_single_example(serialized_example, features=feature_structure) 

Senza questo ho continuato a ottenere il "random_shuffle_queue è chiuso e presenta elementi insufficienti" errore che sto indovinando è perché il mio esempio analizzato non aveva i dati in esso.

1

Questo potrebbe anche essere causato da un errato nome del file di registrazione tf che non esiste affatto. Assicurati di aver specificato i percorsi file corretti prima di fare altri controlli.