1
$\begingroup$

I am currently working on designing a certain number of CNN for extracting features from images.

The images are spectogram, and each have a shape being (276,x,3). X is here the number of column, which incidently also the length of the feature vector that should be created.

So the cnn somehow has to use a kernel that has to be 276 rows and 1 column wide, but is it possible in keras to make a 2d kernel and perform 1d convolution. The most important factor is the 1d convolution and the shape of the 2d kernel, as it is being used to alter the importance of some of the entries in the spectogram.

$\endgroup$
1
  • $\begingroup$ thanks for the discussion. I have a related question: Can you "flip" the dimension of convolutions arbitrarily? For example, if I wanted to convolve across y-axis? Does this also hold for the 1D conv operation? $\endgroup$ Jan 29 '19 at 19:59
1
$\begingroup$

Designing CNN that does one column convolution across the x-axis

So the cnn somehow has to use a kernel that has to be 276 rows and 1 column wide, but is it possible in keras to make a 2d kernel and perform 1d convolution.

I'm not sure I understand your question correctly, but if you have input images that are 276 high, X=500 wide and have 3 color channels, then the following performs column-wise convolutions across the X-axis:

rows, cols, chans = 276, 500, 3

...
model.add(Convolution2D(64, rows, 1, input_shape=(rows, cols, chans)))
...

The output shape of this layer will be (1, 500, 64).

I inserted "64" as the number of filters.. you can set that to whatever you need / whatever works best.

Note: shapes are specified in tensorflow mode (i.e. the order is (rows, cols, channels)). Depending on your configuration you might have to change those shapes to theano mode: (channels, rows, cols).

So the cnn somehow has to use a kernel that has to be 276 rows and 1 column wide,

It actually has to use a kernel that is 276 rows, 1 column and 3 channels wide since your input images have 3 channels.. it would be 276 rows and 1 column wide if you used grayscale images.. but that shouldn't matter.

$\endgroup$
3
  • $\begingroup$ Thanks for the response. Just to be clear does this peform 1d convolution. Meaning that in only moves in one direction rather than 2d? Is it possible to define the entries in the kernel? $\endgroup$ Mar 9 '17 at 18:02
  • $\begingroup$ And the input shape... How am i going to apply this all the images, since col is different for all the images ? $\endgroup$ Mar 9 '17 at 18:05
  • 1
    $\begingroup$ Yes, this will only move in one direction. Since we specified a kernel size of 276x1 it can not move in the Y direction, only in the X direction. Input shape: Keras' CNNs require a fixed shape. To keep it simple, I'd just split your images into chunks with the same width. If you really need variable length inputs, you'll probably have to use RNNs. $\endgroup$
    – stmax
    Mar 10 '17 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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