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

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

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

For the 3D case, you can use the deepnetwork designer to build an equivalent sub-network out of functionLayers and a depthConcatenationLayer, e.g.,
The functionLayers serve to extract a subset of channels from the input 3D image and can be built using the following
subsets={1:2,3:4};
subslayers=channelSubset(subsets);
function subslayers=channelSubset(subsets)
N=numel(subsets);
for i=1:N
subslayers(i)=functionLayer(@(z) z(:,:,:,subsets{i}),'Name',"Group"+i); %#ok<AGROW>
end
end
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.
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

Asked:

on 26 Apr 2023

Edited:

on 26 Apr 2023

Community Treasure Hunt

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

Start Hunting!