%% Perform Grouped Convolution
% Convolve the input data in three groups of two channels each. Apply four filters per group.
% Create the input data as 10 observations of size 100-by-100 with six channels.

height = 100;
width = 100;
channels = 6;
numObservations = 10;

X = rand(height,width,channels,numObservations);
dlX = dlarray(X,'SSCB');

% Initialize the convolutional filters. Specify three groups of convolutions that each apply four convolution filters to two channels of the input data.

filterHeight = 8;
filterWidth = 8;
numChannelsPerGroup = 2;
numFiltersPerGroup = 4;
numGroups = 3;

weights = rand(filterHeight,filterWidth,numChannelsPerGroup,numFiltersPerGroup,numGroups);

% Initialize the bias term.

bias = rand(numFiltersPerGroup*numGroups,1);

% Perform the convolution.

dlY = dlconv(dlX,weights,bias);
size(dlY)
dims(dlY)

% The 12 channels of the convolution output represent the three groups of convolutions with four filters per group.
% Copyright 2019 The MathWorks, Inc.