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

6 次查看(过去 30 天)
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?

采纳的回答

Matt J
Matt J 2023-4-26
A 1D image is a special case of a 2D image, so you should be able to use groupedConvolution2dLayers for the 1D case.
  3 个评论
Artem Lensky
Artem Lensky 2023-4-26
编辑:Artem Lensky 2023-4-26
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 2023-4-26
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.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by