[英]Reading and Batching Sequence data in Tensorflow with TFRecords
嗨,我目前正在嘗試使用tensorflow批處理可變寬度的圖像。 例如我正在處理尺寸為50*245, 50*235, 50*265...and so on
我遵循了在網上找到的基本管道,首先將數據序列化,然后使用tf.train.SequenceExample().
將其寫入tfrecord文件中tf.train.SequenceExample().
我存儲不同寬度的圖像,例如245, 235, 265 ...and so on
並使用此代碼存儲像素數據。
example=tf.train.SequenceExample()
#First we store our image width in 'input_length' feature
example.context.feature['input_length'].int64_list.value.append(sequence_length)
feature_input=example.feature_lists.feature_list['input']
#Then we store pixel values in 'input' feature (our sequential data)
for pixel in image :
feature_input.feature.add().int64_list.value.append(pixel)
#write in the TFRecord file
writer.write(example.SerializeToString())
然后,我們打開TFRecord文件並指定對順序數據的解析
#Definition of data parsing
context_features = {
'input_length':tf.FixedLenFeature([],dtype=tf.int64)
}
sequence_features = {
"input":tf.FixedLenSequenceFeature([50,],dtype=tf.int64,allow_missing=False),
}
#Now we parse the examples
length_parsed,sequence_parsed=tf.parse_single_sequence_example(
serialized=serialized_data,
context_features=context_features,
sequence_features=sequence_features
)
input_lengths,input_data=tf.train.batch(
tensors=[length_parsed['input_length'],sequence_parsed['input']],
batch_size=1,
dynamic_pad=True
)
問題是動態填充似乎不起作用(?,50)
當我認為我會獲得進入批處理中最大張量的形狀的張量時(?,50)
我得到了形狀的張量(?,50)
(265,50)
....有人對我在做什么錯有任何想法,或者我沒有指定批處理過程或以上任何過程的想法嗎? 堅持了5天:/
我找到了解決方案...首先,我只將唯一的整數放入我的功能列表中,而不是將“整數列表”放入我的示例中。 所以腳本不明白為什么突然間我要尋找50個分量向量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.