I want to apply a ConvNet on my one dimensional data retrieved from 13 sensors. So, each of my samples consists of 13 channels (of 51 values)

I am using 'conv1d' to apply a ConvNet on my data. The network works nicely, but I wonder how 'conv1d' determines the number of channels for it's filters... To my knowledge, a filter should have an equal number of channels as its input data, which makes it a $5x13$ filter. I set the filter to have a width of 5, but don't need to set the number of channels anywhere.

My question is: how does layer 'conv1' determine it's number of channels?

Below is a portion of my code:

# We have 13 1D channels of 51 points each

# Note that we've indicated -1 for batch size, which specifies that this dimension should be dynamically computed 
# based on the number of input values in features["x"], holding the size of all other dimensions constant.

input_layer = tf.reshape(features["x"], [-1, 51, 13])

# Convolutional Layer #1
# Shouldn't this filter also need to number of channels? 
This should match the input number of channels
conv1 = tf.layers.conv1d(inputs=input_layer, filters=32, kernel_size=5, padding="same", activation=tf.nn.relu)

# Pooling Layer #1
pool1 = tf.layers.max_pooling1d(inputs=conv1, pool_size=2, strides=2)

1 Answer 1


In TensorFlow there are different convolution layers. Conv1d, Conv2d and Conv3d. the first one is used for one dimensional signals like sounds, the second one is used for images, gray-scale or RGB images and both cases are considered to be two dimensional signals. The last one is used for three dimensional signals like video frames, images as two dimensional signals vary during time. In your case Conv1d is used as one dimensional signal and you can specify the number of filters in the arguments of the method. You can take a look at here and here.

  • $\begingroup$ Thanks for your response. The data is 51 (W) * 13 (C), so the filter needs to be 5 (W) * 13 (C) as well, right? $\endgroup$
    – Ben
    Jan 31, 2018 at 9:12
  • $\begingroup$ @Ben if width is 51 yes, each filter, kernel, should have 51 width and 13 channels. In the last link I've provided I've discussed that too. Also our friend Neil has discussed that there nicely too. $\endgroup$ Jan 31, 2018 at 9:16
  • $\begingroup$ Ok, and TF automatically derives the number of channels in the kernel from the input tensor (as this is not really configurable)? $\endgroup$
    – Ben
    Jan 31, 2018 at 9:48
  • $\begingroup$ yes for first part, for second part of your question I've not seen the usage of that unless the paper of Lenet by Lecun. In that paper they hand wired the connections. In TensorFlow there are ways to do that. You can for each kernel define what you want and concat them, although I've never seen its usage. $\endgroup$ Jan 31, 2018 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.