Main Content

maxunpool

Unpool the output of a maximum pooling operation

Description

The maximum unpooling operation unpools the output of a maximum pooling operation by upsampling and padding with zeros.

The maxunpool function applies the maximum unpooling operation to dlarray data. Using dlarray objects makes working with high dimensional data easier by allowing you to label the dimensions. For example, you can label which dimensions correspond to spatial, time, channel, and batch dimensions using the 'S', 'T', 'C', and 'B' labels, respectively. For unspecified and other dimensions, use the 'U' label. For dlarray object functions that operate over particular dimensions, you can specify the dimension labels by formatting the dlarray object directly, or by using the 'DataFormat' option.

Note

To apply maximum unpooling within a layerGraph object or Layer array, use maxUnpooling2dLayer.

example

dlY = maxunpool(dlX,indx,outputSize) upsamples the spatial or time dimensions of input data dlX to match the size outputSize. The data is padded with zeros between the locations of maximum values specified by indx. The input dlX is a formatted dlarray with dimension labels. The output dlY is a formatted dlarray with the same dimension labels as dlX.

dlY = maxunpool(dlX,indx,outputSize,'DataFormat',FMT) also specifies the dimension format FMT when dlX is not a formatted dlarray. The output dlY is an unformatted dlarray with the same dimension order as dlX.

Examples

collapse all

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)
ans = 1×4

    28    28     3   128

dims(dlX)
ans = 
'SSCB'

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)
ans = 1×4

    14    14     3   128

dims(dlY)
ans = 
'SSCB'

View the data size.

dataSize
dataSize = 1×4

    28    28     3   128

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)
ans = 1×4

    28    28     3   128

dims(dlY)
ans = 
'SSCB'

Create a formatted dlarray object containing a batch of 128 sequences of length 100 with 12 channels. Specify the format 'CBT' (channel, batch, time).

miniBatchSize = 128;
sequenceLength = 100;
numChannels = 12;
X = rand(numChannels,miniBatchSize,sequenceLength);
dlX = dlarray(X,'CBT');

View the size and format of the input data.

size(dlX)
ans = 1×3

    12   128   100

dims(dlX)
ans = 
'CBT'

Apply 1-D maximum pooling with pooling regions of size 2 with a stride of 2 using the maxpool function by specifying the 'PoolFormat' and 'Stride' options.

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

View the size and format of the output.

size(dlY)
ans = 1×3

    12   128    50

dims(dlY)
ans = 
'CBT'

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)
ans = 1×3

    12   128   100

dims(dlY)
ans = 
'CBT'

Input Arguments

collapse all

Input data, specified as a formatted or unformatted dlarray object.

If dlX is an unformatted dlarray, then you must specify the format using the 'DataFormat' option.

The function, unpools the 'S' (spatial) and 'T' dimensions of the data to have sizes given by outputSize.

Indices of maximum values in each pooled region, specified as a dlarray.

Use the indices output of the maxpool function as the indx input to maxunpool.

Size of the output feature map, specified as a numeric array.

Use the size output of the maxpool function as the outputSize input to maxunpool.

Dimension order of unformatted input data, specified as the comma-separated pair consisting of 'DataFormat' and a character array or string FMT that provides a label for each dimension of the data. Each character in FMT must be one of the following:

  • 'S' — Spatial

  • 'C' — Channel

  • 'B' — Batch (for example, samples and observations)

  • 'T' — Time (for example, sequences)

  • 'U' — Unspecified

You can specify multiple dimensions labeled 'S' or 'U'. You can use the labels 'C', 'B', and 'T' at most once.

You must specify 'DataFormat',FMT when the input data dlX is not a formatted dlarray.

Example: 'DataFormat','SSCB'

Data Types: char | string

Output Arguments

collapse all

Unpooled data, returned as a dlarray. The output dlY has the same underlying data type as the input dlX.

If the input data dlX is a formatted dlarray, then dlY has the same dimension labels as dlX. If the input data is not a formatted dlarray, then dlY is an unformatted dlarray with the same dimension order as the input data.

Extended Capabilities

Introduced in R2019b