【发布时间】:2020-11-30 04:39:28
【问题描述】:
在将输入输入到我的网络之前,我需要进行一些预处理。我正在研究我的数据迭代器并制作一些函数来准备数据。我的火车组是一个大文件,每一行都有以下方案。每行以分号分隔,也可以为空。然后每个拆分包含不同的事件,这些事件以 como 分隔,最后每个观察有 5 个以冒号分隔的信号。
1:1560629595635:183.94:z1:Happy,2:1560629505635:100:z1:Sad;5:1561929595635:1:z1:Happy,13:1561629595635:12:j1:Sad;50:15616295956351:10:f1:Sad
我的目标是按以下顺序拆分每一行:
1. ';' Split
2. ',' Split
3. ':' Split
*Note: length after the last split = 5
在我编写的以下函数中,如果我为函数指定 indx,它仅适用于“;”的一个片段输出分裂。
def __semicolon_coma_colon_split(line, table, indx):
sources = tf.strings.split(line, ';')
pairs = tf.strings.split(sources[indx], ',')
items = tf.strings.split(pairs, ':').to_tensor()
return (tf.strings.to_number(items[:, 0], out_type=tf.int32),
tf.strings.to_number(items[:, 1], out_type=tf.int64),
tf.strings.to_number(items[:, 2], out_type=tf.float32),
tf.cast(table.lookup(items[:, 3]), tf.int32),
tf.cast(table.lookup(items[:, 4]), tf.int32))
而当前的输出形状是
(<tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>)
但是,我需要在 ';' 之后的所有拆分上同时运行它并且预期的输出张量看起来像一个元组的元组,每个元组包含 5 个张量;
((<tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>),
(<tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>, <tf.Tensor: shape=(2,)>),
(<tf.Tensor: shape=(1,)>, <tf.Tensor: shape=(1,)>, <tf.Tensor: shape=(1,)>, <tf.Tensor: shape=(1,)>, <tf.Tensor: shape=(1,)>))
【问题讨论】:
标签: python tensorflow machine-learning deep-learning tensorflow-datasets