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 labels 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.8147    0.2785    0.9572    0.7922    0.6787    0.7060
    0.9058    0.5469    0.4854    0.9595    0.7577    0.0318
    0.1270    0.9575    0.8003    0.6557    0.7431    0.2769
    0.9134    0.9649    0.1419    0.0357    0.3922    0.0462
    0.6324    0.1576    0.4218    0.8491    0.6555    0.0971
    0.0975    0.9706    0.9157    0.9340    0.1712    0.8235

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

    0.9058    0.9595    0.7577
    0.9649    0.8003    0.7431
    0.9706    0.9340    0.8235

indx = 9×1    
     2
    10
    12
    20
    15
    24
    26
    27
    36

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         0
    0.9058         0         0    0.9595    0.7577         0
         0         0    0.8003         0    0.7431         0
         0    0.9649         0         0         0         0
         0         0         0         0         0         0
         0    0.9706         0    0.9340         0    0.8235

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 numeric array.

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 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', or 'T' at most once.

You must specify 'DataFormat' when the input data dlX is an unformatted 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