Channel-wise convolution deep learning layer for 1d and 3d data i.e. groupedCon​volution1d​Layer, groupedCon​volution3d​Layer

8 views (last 30 days)
I am looking to implement a layer for channel-wise convolution similar to groupedConvolution2dLayer(filtSize, 1, "channel-wise"...). Unfortunately there are no 1D and 3D analogs of groupedConvolution2dLayer.
Any recommendations would be helpful?

Accepted Answer

Matt J
Matt J on 26 Apr 2023
A 1D image is a special case of a 2D image, so you should be able to use groupedConvolution2dLayers for the 1D case.
  3 Comments
Artem Lensky
Artem Lensky on 26 Apr 2023
Edited: Artem Lensky on 26 Apr 2023
Matt, thank you for the prompt response! Very much appreciated.
The input data for 1D case are 1D signals (in principal of different length, that is why I chose sequenceInputLayer as input layer). The tensor that is passed to the convolution layer is of "CBT" shape. To make it compatible with groupedConvolution2dLayer, I implemented two simple layers (cbt2sscbLayer and sscb2cbtLayer) that map "CBT" to "SSCB" and then "SSCB" to "CBT". So the network is organized in the following way
[...
cbt2sscbLayer()...
groupedConvolution2dLayer([recSize 1], 1, "channel-wise")...
sscb2cbtLayer()...
instanceNormalizationLayer()...
]
The mapping layers imlement method predict as follows
% cbt2sscbLayer
function Z = predict(layer, X)
idx = finddim(X, "T");
numSamples = X.size(idx(1));
idx = finddim(X, "C");
numChannels = X.size(idx);
idx = finddim(X, "B");
if(isnan(X.size(idx)))
numBatches = 1;
else
numBatches = X.size(idx);
end
X = dlarray(X,'UUU');
Z = ones(numSamples, 1, numChannels, numBatches);
Z(:,1,:,:) = permute(X, [3, 1, 2]);
Z = dlarray(Z,'SSCB');
end
and
% sscb2cbtLayer
function Z = predict(layer, X)
idx = finddim(X, "S");
numSamples = X.size(idx(1));
idx = finddim(X, "C");
numChannels = X.size(idx);
idx = finddim(X, "B");
if(isnan(X.size(idx)))
numBatches = 1;
else
numBatches = X.size(idx);
end
X = X.reshape([numSamples, numChannels, numBatches]);
X = dlarray(X,'UUU');
Z = X.permute([2 3 1]);
Z = dlarray(Z,'CBT');
end
Unfortunately the model is not able to learn.
Do I need to implement function backward? Any recommendations would be apprecitated.
Artem Lensky
Artem Lensky on 26 Apr 2023
UPDATE: The solution above seemed to work for 1D signals. It didn't work inititally because of some hyperparameter that is not relevant to the implementation above.
I will do a bit of testing and then will try implementing/testing the idea for the 3D case.

Sign in to comment.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!