%% Unpool 2-D Maximum Pooled Data
% 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)

% Pool the data to maximum values over pooling regions of size 2 using a stride of 2.

[dlY,indx,dataSize] = maxpool(dlX,2,'Stride',2);

% View the size and format of the pooled data.

size(dlY)
dims(dlY)

% View the data size.

dataSize

% Unpool the data using the indices and data size from the maxpool operation.

dlY = maxunpool(dlY,indx,dataSize);

% View the size and format of the unpooled data.

size(dlY)
dims(dlY)

% Copyright 2020 The MathWorks, Inc.