Reputation: 343
I am trying to implement CNN using tensorflow on temporal accelerometer signal.
I want to perform 1-D convolution:
tf.nn.conv1d(x, W, stride=1, padding='VALID')
Convolution window size is 20 samples and stride of 1 with 32 features and Valid padding
I want to apply Max-Pooling with window size of 10 samples:
tf.nn.max_pool(x, ksize=[1, 1, 10, 1], strides= [1, 1, 2, 1], padding='VALID')
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
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