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.

Note

This function applies the maximum unpooling operation to dlarray data. If you want to apply maximum unpooling within a layerGraph object or Layer array, use the following layer:

example

dlY = maxunpool(dlX,indx,outputSize) upsamples the spatial 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 the input data as a single observation of random values with a height and width of six and a single channel.

height = 6;
width = 6;
channels = 1;
observations = 1;

X = rand(height,width,channels,observations);
dlX = dlarray(X,'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);
dlX = 
  6(S) × 6(S) × 1(C) × 1(B) dlarray

    0.8206    0.5945    0.6960    0.1508    0.9857    0.0168
    0.9171    0.7565    0.9339    0.0515    0.0900    0.2920
    0.9295    0.7223    0.4381    0.4417    0.2460    0.9403
    0.6107    0.9710    0.4156    0.2089    0.1359    0.7609
    0.3046    0.4560    0.4689    0.5395    0.3991    0.6321
    0.8533    0.4369    0.2349    0.7844    0.7390    0.5615


dlY = 
  3(S) × 3(S) × 1(C) × 1(B) dlarray

    0.9171    0.9339    0.9857
    0.9710    0.4417    0.9403
    0.8533    0.7844    0.7390

indx = 
  3(S) × 3(S) × 1(C) × 1(B) dlarray

     2    14    25
    10    21    33
     6    24    30


dataSize = 1×4    
     6     6     1     1

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

dlY = maxunpool(dlY,indx,dataSize)
dlY = 
  6(S) × 6(S) × 1(C) × 1(B) dlarray

         0         0         0         0    0.9857         0
    0.9171         0    0.9339         0         0         0
         0         0         0    0.4417         0    0.9403
         0    0.9710         0         0         0         0
         0         0         0         0         0         0
    0.8533         0         0    0.7844    0.7390         0

Input Arguments

collapse all

Input data, specified as a dlarray with or without dimension labels. When dlX is not a formatted dlarray, you must specify the dimension label format using 'DataFormat',FMT.

Unpooling acts on dimensions that you specify as spatial dimensions using the 'S' dimension label. dlX must have at least one 'S' dimension. You can specify up to three dimensions in dlX as 'S' dimensions. Use the dlY output of the maxpool function as the dlX input to maxunpool.

Data Types: single | double

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

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

Data Types: single | double

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

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

Data Types: single | double

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, dlY has the same dimension labels as dlX. If the input data is not a formatted dlarray, dlY is an unformatted dlarray with the same dimension order as the input data.

Extended Capabilities

Introduced in R2019b