%% Perform 2-D Global Average Pooling
% Create a formatted dlarray object containing a batch of 128 28-by-28 images with 3 channels. Specify the format 'SSCB' (spatial, spatial, channel, batch).

miniBatchSize = 128;
inputSize = [28 28];
numChannels = 3;
X = rand(inputSize(1),inputSize(2),numChannels,miniBatchSize);
dlX = dlarray(X,'SSCB');

% View the size and format of the input data.

size(dlX)
dims(dlX)

% Apply 2-D global average pooling using the avgpool function by specifying the 'global' option.

dlY = avgpool(dlX,'global');

% View the size and format of the output.

size(dlY)
dims(dlY)

% Copyright 2020 The MathWorks, Inc.