Reputation: 141
i am trying to model time series data in to a convolution NN with tensorflow. My time series data format is as follows
[timestamp, x, y, z]
I want to create 300 time stamp windows for three channels (x, y, z). Therefore i have pre-processed the data as follows and when i feed this in to the tf.layers.conv1d i use the input of following reshapings
[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]
which of this versions is correct reshaping considering my original data set? Or are both of them not right? In that case what is the correct way to feed this data in to the convolution layer?
I have tried both and the accuracy results are very low (less than 40%).
Thanks in advance!
Upvotes: 1
Views: 1068
Reputation: 1829
Method 2 is correct. You can verify it by running the following simple example code. Here, My bacth_size =2 and instead of 300 I just used 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
Therefore, the input (batch_size=2, width=9, num_channels=3) to the tf.layers.conv1d should have the following shape.
[[[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]]]
Upvotes: 1