%% Perform Channel-Wise Separable Convolution
% Separate the input data into channels and perform convolution on each channel separately.
% Create the input data as a single observation with a size of 64-by-64 and 10 channels. Create the data as an unformatted dlarray.

height = 64;
width = 64;
channels = 10;

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

% Initialize the convolutional filters. Specify an ungrouped convolution that applies a single convolution to all three channels of the input data.

filterHeight = 8;
filterWidth = 8;
numChannelsPerGroup = 1;
numFiltersPerGroup = 1;
numGroups = channels;

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

% Initialize the bias term.

bias = rand(numFiltersPerGroup*numGroups,1);

% Perform the convolution. Specify the dimension labels of the input data using the 'DataFormat' option.

dlY = dlconv(dlX,weights,bias,'DataFormat','SSC');
size(dlY)

% Each channel is convolved separately, so there are 10 channels in the output.
% Copyright 2019 The MathWorks, Inc.