2017-07-12 13 views
0

TFRecordファイルから "many"(〜500件以上)のイベントを読み込めません。私は500回のイベントでファイルを作成した場合、すべてが正常であるが、私は、ファイルを読み込んで解析しようとすると、500以上のエラーが発生します。TensorFlow多くの画像を含むTFRecordが読み込み中にクラッシュする

W tensorflow/core/framework/op_kernel.cc:993] Invalid argument: Could not parse example input, value: 
... 
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb5 in position 40: invalid start byte 

画像は((N, 127, 50, 2)に形状(N, 2, 127, 50)と山車の再成形されています読み込み中)。私は2つの異なる方法を書こうとしました:バイトのリストと浮動小数点のリストとして、両方とも同じ方法で失敗します。 「バイト法」、コードの業務部品の

は以下のとおりです。

def write_to_tfrecord(data_dict, tfrecord_file): 
    writer = tf.python_io.TFRecordWriter(tfrecord_file) 
    features_dict = {} 
    for k in data_dict.keys(): 
     features_dict[k] = tf.train.Feature(
      bytes_list=tf.train.BytesList(value=[data_dict[k]['byte_data']]) 
     ) 
    example = tf.train.Example(
     features=tf.train.Features(feature=features_dict) 
    ) 
    writer.write(example.SerializeToString()) 
    writer.close() 

、次に読み:

def tfrecord_to_graph_ops_xtxutuvtv(filenames): 
    def process_hitimes(inp, shape): 
     hitimes = tf.decode_raw(inp, tf.float32) 
     hitimes = tf.reshape(hitimes, shape) 
     hitimes = tf.transpose(hitimes, [0, 2, 3, 1]) 
     return hitimes 

    file_queue = tf.train.string_input_producer(filenames, name='file_queue') 
    reader = tf.TFRecordReader() 
    _, tfrecord = reader.read(file_queue) 

    tfrecord_features = tf.parse_single_example(
     tfrecord, 
     features={ 
      'hitimes-x': tf.FixedLenFeature([], tf.string), 
     }, 
     name='data' 
    ) 
    hitimesx = proces_hitimes(
     tfrecord_features['hitimes-x'], [-1, 2, 127, 50] 
    ) 
    return hitimesx 

(通常、私は読み取りと書き込み、他のテンソルをも、しかし、問題はただ1つあります)

"floatメソッド"の場合、コードは次のようになります。

def write_to_tfrecord(data_dict, tfrecord_file): 
    writer = tf.python_io.TFRecordWriter(tfrecord_file) 
    features_dict = {} 
    features_dict['hitimes-x'] = tf.train.Feature(
     float_list=tf.train.FloatList(
      value=data_dict['hitimes-x']['data'].flatten() 
     ) 
    ) 
    example = tf.train.Example(
     features=tf.train.Features(feature=features_dict) 
    ) 
    writer.write(example.SerializeToString()) 
    writer.close() 

と、読書:

def tfrecord_to_graph_ops_xtxutuvtv(filenames): 
    def process_hitimes(inp, shape): 
     hitimes = tf.sparse_tensor_to_dense(inp) 
     hitimes = tf.reshape(hitimes, shape) 
     hitimes = tf.transpose(hitimes, [0, 2, 3, 1]) 
     return hitimes 

    file_queue = tf.train.string_input_producer(filenames, name='file_queue') 
    reader = tf.TFRecordReader() 
    _, tfrecord = reader.read(file_queue) 

    tfrecord_features = tf.parse_single_example(
     tfrecord, 
     features={ 
      'hitimes-x': tf.VarLenFeature(tf.float32), 
     }, 
     name='data' 
    ) 
    hitimesx = process_hitimes(
     tfrecord_features['hitimes-x'], [-1, 2, 127, 50] 
    ) 
    return hitimesx 

書き込まれるデータは、タイプのfloat32のnumpyのndarraysです。

これはバグ(私はTensorFlow 1.0を使用しています)だと思うのですが、どちらの方法も〜500画像までうまくいくので、もっと画像を使用しようとすると壊れます。私はドキュメントを見て、読者と作家が大きなファイルを扱うことができるように追加すべき引数があるかどうかを見てきましたが、何も見つかりませんでした(そして、500イメージはあまりありません。それらの何百万という)。

アイデア?今日TensorFlow 1.2で試してみる予定ですが、まだチャンスがありませんでした。

+0

私はイベントの数と関係があることを非常に疑っています。私はtfrecordファイルで作業しています。それぞれに10mlnのイベントがあり、すべてが正常です。 1つの画像を1k回保存して、数字500とは何の関係もないことを確認することをお勧めします。その後、どの画像があなたの読者を壊して、あなたがすでに持っているものとどのように違うのかを確認します。 –

+0

イベント500ではありませんでした。 TF 1.0のバグだと思う。 –

答えて

0

私はTF 1.2.1にアップグレードし、上記の問題はByteList秒を使用して、少なくともとき(消えた - 私はより多くの慣用TensorFlowあるアプローチわからないんだけど、ByteListとバイトのデータがより簡単なコードで、すべてを処理しますここで私)。

私は大きなファイル(今、私はTFレコードファイルに、25Kを超えるイベント、多分より多くを書くことができます)を読み取るときに発生すると考えてい新しい問題があります - つまり、そのTFがで全体のファイルを開くには私はデータ処理のための私のテストマシン以上のものですが、私はTensorFlowにこれを責めません(私は便利な圧縮やチャンクスキームのいくつかの並べ替えを考え出す必要がありますが、等。)。

関連する問題