【问题标题】:time series Input for 1D convolution with tensorflow使用张量流进行一维卷积的时间序列输入
【发布时间】:2017-11-16 16:53:13
【问题描述】:

我正在尝试使用 tensorflow 将时间序列数据建模到卷积神经网络中。 我的时间序列数据格式如下

[timestamp, x, y, z]

我想为三个通道(x、y、z)创建 300 个时间戳窗口。因此,我对数据进行了如下预处理,当我将其输入到 tf.layers.conv1d 时,我使用以下重塑的输入

[1]
[x,y,z],[x,y,z],...[x,y,z] of size 3*300
#input shape is [-1, 3*300]
input = tf.reshape(input, shape = [-1, 300, 3])
#input shape is [-1, 300, 3]

[2]
[x,x,..x],[y,y,..y],[z,z...z] of size 300*3
#input shape is [-1, 300*3]
input = tf.reshape(input, shape = [-1, 300, 3])
#input shape is [-1, 300, 3]

考虑到我的原始数据集,哪些版本是正确的重塑? 还是两者都不对?在那种情况下,将这些数据输入卷积层的正确方法是什么?

我都尝试过,但准确度结果非常低(低于 40%)。

提前致谢!

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    方法二是正确的。您可以通过运行以下简单示例代码来验证它。在这里,我的 bacth_size =2 而不是 300,我只使用了 9。

    #Method1
    input1 = np.array([[1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3],
                       [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]])
    print(input1.shape)  # prints (2, 3*9)
    out1 = tf.reshape(input1, shape=[-1, 9, 3])
    
    #Method2
    input2 = np.array([[1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3],
                       [1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3]])
    print(input2.shape)  # prints (2, 3*9)
    out2 = tf.reshape(input2, shape=[-1, 9, 3])
    
    sess = tf.Session()
    with sess.as_default():
        print(out1.eval())  # runs out1
        print(out2.eval())  # runs out2
    

    因此,tf.layers.conv1d 的输入 (batch_size=2, width=9, num_channels=3) 应具有以下形状。

    [[[x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]]
    
     [[x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]
      [x y z]]]
    

    【讨论】:

    • 这是您答案中 Method1 (out1) 的输出。 ?
    • 是的,是一样的。
    猜你喜欢
    • 2020-05-14
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-26
    相关资源
    最近更新 更多