I'm still quite novice with regard to convolutional networks. I'm trying to implement multiple Conv1D layers in Keras. Unfortunately, after the very first layer, any subsequent layers throw the following error:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by subtracting 8 from 1 for 'conv1d_2/convolution/Conv2D' (op: 'Conv2D') with input shapes: [?,1,1,32], [1,8,32,32].
I had thought it may have something to do with the size reduction due to strides, but it still does not work after setting strides=1
for both Conv1D lines. Here is my code. If the for loop runs, then the error is thrown.
#State branch
x = Conv1D(layerSize,8,strides=1)(inputState)
x = Activation("relu")(x)
for l in range(conv1Layer-1):
x = Conv1D(layerSize,8,strides=1)(x)
x = Activation("relu")(x)
x = MaxPooling1D(pool_size=1)(x)
x = Flatten()(x)
x = Model(inputs=inputState, outputs=x)
Any help or advice would be greatly appreciated. Thank you!
If you do not want the length to change after the convolution consider specifying padding='same'
in the constructor of Conv1d
.
For more info see the docs .
The kernel_size must be changed to 1 after the first layer.
EDIT: Or the padding must be set to the same! Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.