2017-07-10 6 views
0

tfrecordsファイルの画像とテキストを読むには、fsns/train/train-00511-of-00512HiFSNS datasetsにします。 しかし、ときに私の仕事はTfrecordsガイドの案内に従ってください:link、それは次のエラーメッセージが表示されます。FSNSデータセットでイメージとテキストを読み取る方法は?

InvalidArgumentError (see above for traceback): Name: <unknown>, Feature: encoded (data type: string) is required but could not be found. 
    [[Node: ParseSingleExample/ParseExample/ParseExample = ParseExample[Ndense=4, Nsparse=0, Tdense=[DT_STRING, DT_INT64, DT_STRING, DT_INT64], dense_shapes=[[], [], [], []], sparse_types=[], _device="/job:localhost/replica:0/task:0/cpu:0"](ParseSingleExample/ExpandDims, ParseSingleExample/ParseExample/ParseExample/names, ParseSingleExample/ParseExample/ParseExample/dense_keys_0, ParseSingleExample/ParseExample/ParseExample/dense_keys_1, ParseSingleExample/ParseExample/ParseExample/dense_keys_2, ParseSingleExample/ParseExample/ParseExample/dense_keys_3, ParseSingleExample/ParseExample/Const, ParseSingleExample/ParseExample/Const_1, ParseSingleExample/ParseExample/Const_2, ParseSingleExample/ParseExample/Const_3)]] 

キーの名前が間違っているようですか?私のコードが添付されているか、作成者が他のコードをチェックしてバグを修正するのに役立つでしょうか?

import tensorflow as tf 
import skimage.io as io 

IMAGE_HEIGHT = 384 
IMAGE_WIDTH = 384 

tfrecords_filename = '/home/wangjianbo_i/google_model/MyCode/models/attention_ocr/python/datasets/data/fsns/train/train-00511-of-00512' 

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={ 
     'height': tf.FixedLenFeature([], tf.int64), 
     'width': tf.FixedLenFeature([], tf.int64), 
     'encoded': tf.FixedLenFeature([], tf.string), 
    'text':tf.FixedLenFeature([], tf.string) 
     }) 

    image = tf.decode_raw(features['encoded'], tf.uint8) 
    text = tf.decode_raw(features['text'], tf.uint8) 

    height = tf.cast(features['height'], tf.int32) 
    width = tf.cast(features['width'], tf.int32) 

    image_shape = tf.stack([height, width, 3]) 

    image = tf.reshape(image, image_shape) 

    image_size_const = tf.constant((IMAGE_HEIGHT, IMAGE_WIDTH, 3), dtype=tf.int32) 

    resized_image = tf.image.resize_image_with_crop_or_pad(image=image, 
              target_height=IMAGE_HEIGHT, 
              target_width=IMAGE_WIDTH) 

    images = tf.train.shuffle_batch([resized_image], 
               batch_size=2, 
               capacity=30, 
               num_threads=2, 
               min_after_dequeue=10) 

    return images,text 


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

image,text = read_and_decode(filename_queue) 

init_op = tf.group(tf.global_variables_initializer(), 
        tf.local_variables_initializer()) 

with tf.Session() as sess: 

    sess.run(init_op) 

    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 

    # Let's read off 3 batches just for example 
    for i in xrange(3): 

     img,text= sess.run([image,text]) 
    print img,text 
     print(img[0, :, :, :].shape) 
     print('current batch') 

     io.imshow(img[0, :, :, :]) 
     io.show() 

     io.imshow(img[1, :, :, :]) 
     io.show() 

    coord.request_stop() 
    coord.join(threads) 
+1

いいえ、ここにコードを付ける必要があります。そうしないと、問題を修正してコードを変更するとこの質問は役に立たなくなります。 –

+0

Thx、私はそれを編集します! –

答えて

0

FSNSデータセットを読むには、https://github.com/tensorflow/models/blob/master/attention_ocr/python/datasets/fsns.pyを直接または参照として使用できます。

提供したコードスニペットで機能キーが正しくない - 「画像/」プレフィックスがありません。 '画像'の代わりに '画像/コード'、 '画像'の代わりに '画像/幅'などが必要です。 paperの表4を参照してください。

+0

実際には、紙を読んだ後、前のコードでは、「符号化」ではなく「画像/符号化」を使用しますが、動作しません。だから私は "エンコードされた"を使用して同じ結果を得ようとします。だから、私は "イメージ/エンコード"の代わりに "イメージ/エンコード"を使うべきでしょうか? –

関連する問題