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で試してみる予定ですが、まだチャンスがありませんでした。
私はイベントの数と関係があることを非常に疑っています。私はtfrecordファイルで作業しています。それぞれに10mlnのイベントがあり、すべてが正常です。 1つの画像を1k回保存して、数字500とは何の関係もないことを確認することをお勧めします。その後、どの画像があなたの読者を壊して、あなたがすでに持っているものとどのように違うのかを確認します。 –
イベント500ではありませんでした。 TF 1.0のバグだと思う。 –