【发布时间】:2016-02-06 00:18:16
【问题描述】:
我想根据时间信号的特征使用 Tensorflow 训练网络。数据在E 3 秒的时期被分割,每个时期都有F 的特征。因此,数据具有以下形式
Epoch | Feature 1 | Feature 2 | ... | Feature F |
-------------------------------------------------
1 | .. | .. | | .. |
| .. | .. | | .. |
E | .. | .. | | .. |
将数据加载到 Tensorflow,我正在尝试遵循 cifar 示例并使用 tf.FixedLengthRecordReader。因此,我获取了数据,并将其保存到类型为 float32 的二进制文件中,第一个标签用于第一个 epoch,然后是第一个 epoch 的 F 特征,然后是第二个,等等。
然而,将其读入 TensorFlow 对我来说是一个挑战。这是我的代码:
def read_data_file(file_queue):
class DataRecord(object):
pass
result = DataRecord()
#1 float32 as label => 4 bytes
label_bytes = 4
#NUM_FEATURES as float32 => 4 * NUM_FEATURES
features_bytes = 4 * NUM_FEATURES
#Create the read operator with the summed amount of bytes
reader = tf.FixedLengthRecordReader(record_bytes=label_bytes+features_bytes)
#Perform the operation
result.key, value = reader.read(file_queue)
#Decode the result from bytes to float32
value_bytes = tf.decode_raw(value, tf.float32, little_endian=True)
#Cast label to int for later
result.label = tf.cast(tf.slice(value_bytes, [0], [label_bytes]), tf.int32)
#Cast features to float32
result.features = tf.cast(tf.slice(value_bytes, [label_bytes],
[features_bytes]), tf.float32)
print ('>>>>>>>>>>>>>>>>>>>>>>>>>>>')
print ('%s' % result.label)
print ('%s' % result.features)
print ('>>>>>>>>>>>>>>>>>>>>>>>>>>>')
打印输出为:
Tensor("Cast:0", shape=TensorShape([Dimension(4)]), dtype=int32)
Tensor("Slice_1:0", shape=TensorShape([Dimension(40)]), dtype=float32)
这让我感到惊讶,因为我已经将值转换为 float32,我预计尺寸分别为 1 和 10,这是实际数字,但它们是 4 和 40,对应于字节长度。
怎么会?
【问题讨论】:
标签: python tensorflow