2017-07-11 26 views
3

のは、我々はこのようなデータサンプルをTFRecordを提出しているとしましょう:encoded_jpgここTFRecordデータサンプルを可変長文字列でデコードするには?

def _bytes_feature(value): 
    return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) 

def _float32_feature(value): 
    return tf.train.Feature(float_list=tf.train.FloatList(value=value)) 

example = tf.train.Example(features=tf.train.Features(feature={ 
    'image/encoded': _bytes_feature(encoded_jpg), 
    'label': _float_list_feature(label), 
})) 

異なる画像のためにはかなり異なる可能性がその長さのコード化された32×32のJPG画像の生の値です。 labelは、固定長のベクトルです。

は、固定長フィールドの場合、人は常にサンプルを復号化するために、次のようなものを使用することができます。

features = tf.parse_single_example(
    serialized_example, 
    features = { 
     'image/encoded': tf.FixedLenFeature([], tf.string) 
     'label': tf.FixedLenFeature([], tf.float32) 
    } 

) 

しかし、ここでimage/encodedの長さは一定ではなく、前述の1はもう動作しません。

私はこれにコードを変更した場合:

features = tf.parse_single_example(
    serialized_example, 
    features = { 
     'image/encoded': tf.VarLenFeature(tf.string) 
     'label': tf.FixedLenFeature([], tf.float32) 
    } 
) 

encoded = features['image/encoded'] 

image/encodedがまばらなテンソルのようなものですが、私はこのようなものからイメージをデコードする方法がわかりません。

誰も以前に似たような経験をしていますか?どんな提案も感謝しています。

ありがとうございます!次のコード

+0

をtfrecord読みます。これはスレッドで対処されています:https://stackoverflow.com/questions/41921746/tensorflow-varlenfeature-vs-fixedlenfeature –

+0

ええ、それは、ありがとう! –

答えて

1

は便利なことがあります。tfrecordする

変換:

ex = tf.train.SequenceExample() 
ex.context.feature["length"].int64_list.value.append(label) 
ex_tokens = ex.feature_lists.feature_list["image/encoded"] 
for value in range(encoded_jpg): 
    ex_tokens.feature.add().int64_list.value.append(value) 

with tf.python_io.TFRecordWriter(os.path.join(DATA_PATH, filename) + ".tfrecord") as filew: 
    filew.write(ex.SerializeToString()) 

あなたはまだた `tf.FixedLenFeature`を使用

context_features = { 
    "pose": tf.FixedLenFeature([], dtype=tf.float32) 
} 

sequence_features = { 
    "image/encoded": tf.FixedLenSequenceFeature([], dtype=tf.int64), 
} 

tf_reader = tf.TFRecordReader() 
tf_key, tf_serialized = tf_reader.read(tf_file_queue) 
tf_context, tf_sequence = tf.parse_single_sequence_example(
    serialized = tf_serialized, 
    context_features = context_features, 
    sequence_features = sequence_features 
) 
encoded = tf_sequence['image/encoded'] 
関連する問題