MATLAB: Convolutional 1d net

convolutional neural networksneural networks

I am trying to reproduce the convolution network described in https://arxiv.org/abs/1610.01683 .
Overview of their setup:
However, I seem to run into an obstacle when trying to combine results from different filters. In the paper, the authors have "stacking" layer, where 20 different filtered 1D signals are stacked, to create a sort of spectrogram, which is then fed to another convolutional layer. How does one do a similar thing in matlab? Below is what I have tried, and the error message that I get:
Input:
inputLayer=imageInputLayer([1 6000]);
c1=convolution2dLayer([1 200],20,'stride',1);
p1=maxPooling2dLayer([1 20],'stride',10);
c2=convolution2dLayer([20 30],400,'numChannels',20);
p2=maxPooling2dLayer([1 10],'stride',[1 2]);
f1=fullyConnectedLayer(500);
f2=fullyConnectedLayer(500);
s1=softmaxLayer;
outputLayer=classificationLayer;
convnet=[inputLayer; c1; p1; c2; p2; f1; f2; s1;outputLayer]
opts = trainingOptions('sgdm');
convnet = trainNetwork(allData',labels,convnet,opts);
Output:
convnet =
9x1 Layer array with layers:
1 '' Image Input 1x6000x1 images with 'zerocenter' normalization
2 '' Convolution 20 1x200 convolutions with stride [1 1] and padding [0 0]
3 '' Max Pooling 1x20 max pooling with stride [10 10] and padding [0 0]
4 '' Convolution 400 20x30 convolutions with stride [1 1] and padding [0 0]
5 '' Max Pooling 1x10 max pooling with stride [1 2] and padding [0 0]
6 '' Fully Connected 500 fully connected layer
7 '' Fully Connected 500 fully connected layer
8 '' Softmax softmax
9 '' Classification Output cross-entropy
Error using nnet.cnn.layer.Layer>iInferSize (line 261)
Layer 5 is expected to have a different size.
Error in nnet.cnn.layer.Layer.inferParameters (line 53)
layers = iInferSize(layers, i, inputSize);
Error in trainNetwork (line 61)
layers = nnet.cnn.layer.Layer.inferParameters(layers);
The error message is for layer 5, but I suspect it has to do with layer 4, where the "stacking" takes place. Thoughts?

Best Answer

The 20 filters of c1 are stacked along dim 3, not dim 1. You need to specify a c2 filter size of [1 30], with dim 3 being inferred from the input:
c2 = convolution2dlayer([1 30],400);
Size 20 in dim 3 is inferred here to make the sizes correct, but you can explicitly set 'numChannels' to be certain.
This is the output I got:
9x1 Layer array with layers:
1 'imageinput' Image Input 1x6000x1 images with 'zerocenter' normalization
2 'conv' Convolution 20 1x200x1 convolutions with stride [1 1] and padding [0 0]
3 'maxpool' Max Pooling 1x20 max pooling with stride [10 10] and padding [0 0]
4 'conv_1' Convolution 400 1x30x20 convolutions with stride [1 1] and padding [0 0]
5 'maxpool_1' Max Pooling 1x10 max pooling with stride [1 2] and padding [0 0]
6 'fc' Fully Connected 500 fully connected layer
7 'fc_1' Fully Connected 500 fully connected layer
8 'softmax' Softmax softmax
9 'classoutput' Classification Output cross-entropy with '1', '2', and 498 other classes