0
votes

When taking the one dimensional convolution of a one dimensional array, I receive an error which suggests my second dimension is not big enough.

Here is the overview of the relevant code:

inputs_ = tf.placeholder(tf.float32 ,(None, 45), name='inputs')
x1 = tf.expand_dims(inputs_, axis=1)
x1 = tf.layers.conv1d(x1, filters=64, kernel_size=1, strides=1, padding='valid')

I am hoping to increase the kernel size to 3 such that neighbouring points also influence the output of each input node, however I get the following error:

ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv1d_4/convolution/Conv2D' (op: 'Conv2D') with input shapes: [?,1,1,45], [1,3,45,64].

My guess is that tensorflow is expecting me to reshape my input into two dimensions so that some depth can be used to do the kernel multiplication. Question is why is this the case and what to expect for the layer behaviour based on the input dimensions

1

1 Answers

1
votes

You need to add a Channel dimension as last dimension even if you only have one channel. So this code works:

inputs_ = tf.placeholder(tf.float32 ,(None, 45), name='inputs')
x1 = tf.expand_dims(inputs_, axis=-1)
x1 = tf.layers.conv1d(x1, filters=64, kernel_size=3, strides=1, padding='valid')

So basically the error was caused because your tensor looked like having a width of 1, with 45 channels. TensorFlow was trying to convolve with a kernel size 3 along a size 1 dimension.