%% Create Layers for Channel-Wise Separable Convolution
% A typical convolutional neural network contains blocks of convolution, batch normalization, and ReLU layers. For example,

filterSize = 3;
numFilters = 16;

convLayers = [
    convolution2dLayer(filterSize,numFilters,'Stride',2,'Padding','same')
    batchNormalizationLayer
    reluLayer];

% For channel-wise separable convolution (also known as depth-wise separable convolution), replace the convolution block with channel-wise convolution and point-wise convolution blocks.
% Specify the filter size and the stride in the channel-wise convolution and the number of filters in the point-wise convolution. For the channel-wise convolution, specify one filter per group. For point-wise convolution, specify filters of size 1 in convolution2dLayer.

cwsConvLayers = [
    groupedConvolution2dLayer(filterSize,1,'channel-wise','Stride',2,'Padding','same')
    batchNormalizationLayer
    reluLayer
    
    convolution2dLayer(1,numFilters,'Padding','same')
    batchNormalizationLayer
    reluLayer];

% Create a network containing layers for channel-wise separable convolution.

layers = [
    imageInputLayer([227 227 3])
    
    convolution2dLayer(3,32,'Padding','same')
    batchNormalizationLayer
    reluLayer
    
    groupedConvolution2dLayer(3,1,'channel-wise','Stride',2,'Padding','same')
    batchNormalizationLayer
    reluLayer
    convolution2dLayer(1,16,'Padding','same')
    batchNormalizationLayer
    reluLayer
    
    maxPooling2dLayer(2,'Stride',2)
    
    fullyConnectedLayer(5)
    softmaxLayer
    classificationLayer];

% Copyright 2018 The MathWorks, Inc.