%% Unpool Max Pooling Layer
% Create a max pooling layer, and set the 'HasUnpoolingOutputs' property as true. This property gives the max pooling layer two additional outputs,'indices' and 'size', which enables unpooling the layer. Also create a max unpooling layer.

layers = [
    maxPooling2dLayer(2,'Stride',2,'Name','mpool','HasUnpoolingOutputs',true)
    maxUnpooling2dLayer('Name','unpool');
]

% Sequentially connect layers by adding them to a layerGraph. This step connects the 'out' output of the max pooling layer to the 'in' input of the max unpooling layer.

lgraph = layerGraph(layers)

% Unpool the output of the max pooling layer, by connecting the max pooling layer outputs to the max unpooling layer inputs.

lgraph = connectLayers(lgraph,'mpool/indices','unpool/indices');
lgraph = connectLayers(lgraph,'mpool/size','unpool/size');

% Copyright 2012 The MathWorks, Inc.