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

8 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Matt J
Matt J el 26 de Abr. de 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 comentarios
Artem Lensky
Artem Lensky el 26 de Abr. de 2023
Editada: Artem Lensky el 26 de Abr. de 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 el 26 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by