Salman Shaukat
Salman Shaukat

Reputation: 343

How to set Stride, Filter size in Tensorflow for 1-D signals?

I am trying to implement CNN using tensorflow on temporal accelerometer signal.

But I am getting errors regarding the dimensions of tensors. Any suggestions on how I can set the filter size and stride for both convolution and max-pooling?

Upvotes: 0

Views: 409

Answers (1)

Soroush
Soroush

Reputation: 260

Use tf.layers.max_pooling1d instead:

tf.layers.max_pooling1d(x, pool_size=10, strides=2, padding='valid')

Example:

>>> x = np.reshape(np.arange(20),(1,20,1))
>>> w = np.reshape(np.array([1.,2.,3.]), (3,1,1))
>>> X = tf.placeholder(tf.float64, [1,20,1])
>>> W = tf.constant(w)
>>> h = tf.nn.conv1d(X, W, stride=1, padding='VALID')
>>> p = tf.layers.max_pooling1d(h, pool_size=10, strides=2, padding='valid')
>>> sess.run(h, feed_dict={X:x})
array([[[  8.],
        [ 14.],
        [ 20.],
        [ 26.],
        [ 32.],
        [ 38.],
        [ 44.],
        [ 50.],
        [ 56.],
        [ 62.],
        [ 68.],
        [ 74.],
        [ 80.],
        [ 86.],
        [ 92.],
        [ 98.],
        [104.],
        [110.]]])
>>> sess.run(p, feed_dict={X:x})
array([[[ 62.],
        [ 74.],
        [ 86.],
        [ 98.],
        [110.]]])

Upvotes: 1

Related Questions