Main Content

maxunpool

Unpool the output of a maximum pooling operation

Since R2019b

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 dlnetwork object, use maxUnpooling2dLayer.

example

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

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

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 X 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.

Description of the data dimensions, specified as a character vector or string scalar.

A data format is a string of characters, where each character describes the type of the corresponding data dimension.

The characters are:

  • "S" — Spatial

  • "C" — Channel

  • "B" — Batch

  • "T" — Time

  • "U" — Unspecified

For example, consider an array containing a batch of sequences where the first, second, and third dimensions correspond to channels, observations, and time steps, respectively. You can specify that this array has the format "CBT" (channel, batch, time).

You can specify multiple dimensions labeled "S" or "U". You can use the labels "C", "B", and "T" at most once. The software ignores singleton trailing "U" dimensions after the second dimension.

If the input data is not a formatted dlarray object, then you must specify the FMT option.

For more information, see Deep Learning Data Formats.

Data Types: char | string

Output Arguments

collapse all

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

If the input data X is a formatted dlarray, then Y has the same dimension format as X. If the input data is not a formatted dlarray, then Y is an unformatted dlarray with the same dimension order as the input data.

Algorithms

collapse all

Deep Learning Array Formats

Most deep learning networks and functions operate on different dimensions of the input data in different ways.

For example, an LSTM operation iterates over the time dimension of the input data and a batch normalization operation normalizes over the batch dimension of the input data.

To provide input data with labeled dimensions or input data with additional layout information, you can use data formats.

A data format is a string of characters, where each character describes the type of the corresponding data dimension.

The characters are:

  • "S" — Spatial

  • "C" — Channel

  • "B" — Batch

  • "T" — Time

  • "U" — Unspecified

For example, consider an array containing a batch of sequences where the first, second, and third dimensions correspond to channels, observations, and time steps, respectively. You can specify that this array has the format "CBT" (channel, batch, time).

To create formatted input data, create a dlarray object and specify the format using the second argument.

To provide additional layout information with unformatted data, specify the format using the FMT argument.

For more information, see Deep Learning Data Formats.

Extended Capabilities

Version History

Introduced in R2019b