Skip to content Skip to sidebar Skip to footer

Performing 1d Convolution Using 2d Kernel In Keras

I am currently working on a CNN network, in which i want to apply a 2d kernel on a image, but it only has to perform 1d convolution, meaning that it only has to move along one axis

Solution 1:

Assuming that your image shape=(dim_x, dim_y, img_channels) you can obtain a 1D convolution by setting:

conv1d_on_image = Convolution2D(output_channels, 1, dim_y, border_mode='valid')(input)

Remember that the output from this layer would have shape (dim_x, 1, output_channels). If you want your input to be sequential you may use the Reshape layer by setting:

conv1d_on_image = Reshape((dim_x, output_channels))(conv1d_on_image)

This would produce output with shape (dim_x, output_channels).

An interesting fact is that this is exactly the way how Conv1D works in Keras with tf backend.

Post a Comment for "Performing 1d Convolution Using 2d Kernel In Keras"