2016-09-04 19 views
0

これ以前は、入力画像をTFRecordsファイルに変換しました。あるように見える(TensorFlowでデータを読み取ることができません

def read_and_decode(filename_queue): 
    reader = tf.TFRecordReader() 
    _, serialized_example = reader.read(filename_queue) 
    features = tf.parse_single_example(
     serialized_example, 
     # Defaults are not specified since both keys are required. 
     features={ 
      'image/encoded': tf.FixedLenFeature([], tf.string), 
      'image/class/label': tf.FixedLenFeature([], tf.int64), 
     }) 
    image = tf.decode_raw(features['image/encoded'], tf.uint8) 
    label = tf.cast(features['image/class/label'], tf.int32) 

    reshaped_image = tf.reshape(image,[size[0], size[1], 3]) 
    reshaped_image = tf.image.resize_images(reshaped_image, size[0], size[1], method = 0) 
    reshaped_image = tf.image.per_image_whitening(reshaped_image) 
    return reshaped_image, label 

def inputs(train, batch_size, num_epochs): 
    filename = os.path.join(FLAGS.train_dir, 
          TRAIN_FILE if train else VALIDATION_FILE) 

    filename_queue = tf.train.string_input_producer(
     [filename], num_epochs=num_epochs) 

    # Even when reading in multiple threads, share the filename 
    # queue. 
    image, label = read_and_decode(filename_queue) 

    # Shuffle the examples and collect them into batch_size batches. 
    # (Internally uses a RandomShuffleQueue.) 
    # We run this in two threads to avoid being a bottleneck. 
    images, sparse_labels = tf.train.shuffle_batch(
     [image, label], batch_size=batch_size, num_threads=2, 
     capacity=1000 + 3 * batch_size, 
     # Ensures a minimum amount of shuffling of examples. 
     min_after_dequeue=1000) 
    return images, sparse_labels 

しかし、私はiPython/Jupyter上のバッチを呼び出すしようとすると、プロセスが終了することはありません:今、私はほとんどのチュートリアルから収集し、少し変更した以下のメソッドを持っていますループ)。私はこの方法でそれを呼び出す:

batch_x, batch_y = inputs(True, 100,1) 
print batch_x.eval() 

答えて

1

あなたが入力パイプラインを(ドライブバックグラウンドスレッドを開始しtf.train.start_queue_runners()への呼び出しを、欠けているように見えます例えばこれらのいくつかは、tf.train.shuffle_batch()への呼び出しでnum_threads=2によって暗示スレッドですまた、tf.train.string_input_producer()には背景スレッドが必要です)。以下の小さな変化が、物事のブロックを解除する必要があります。ERROR:tensorflow:QueueRunnerの例外:初期化されていない値を使用しようとinput_producer/limit_epochs /エポック \tは[[ノード:input_producer/

batch_x, batch_y = inputs(True, 100,1) 
tf.initialize_all_variables.run() # Initializes variables. 
tf.initialize_local_variables.run() # Needed after TF version 0.10. 
tf.train.start_queue_runners()  # Starts the necessary background threads. 
print batch_x.eval() 
+0

は今、私は次の警告を取得し、ありがとうlimit = 1000、_device = "/ job:localhost/replica:0/task:0/cpu:0"]のように指定します。 (input_producer/limit_epochs/epochs)]]である。何が原因で起こりうるのか知っていますか? – Kevin

+0

もう一つの欠けている定型文で質問を更新しました。 'tf.initialize_all_variables.run()'(または 'sess.run(tf.initialize_all_variables())')を呼び出す必要があります。それが動作しない場合(バージョンによっては) 'tf.initialize_local_variables()。run()'も追加する必要があります。 – mrry

関連する問題