maxunpool - Unpool the output of a maximum pooling operation - MATLAB (original) (raw)

Unpool the output of a maximum pooling operation

Syntax

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 todlarray 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 thedlarray object directly, or by using the DataFormat option.

[Y](#mw%5F16ab20ae-3108-48b7-8051-f6d9a89008f1) = maxunpool([X](#mw%5F51461d2d-f6c4-4e9a-ad1f-f3f6dc2f245f),[indx](#mw%5Fa4826bb9-3ed5-4c02-bfc3-93170f8ee7f8),[outputSize](#mw%5F0dff3a95-7e20-478b-88f3-110653a973be)) 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 asX.

example

[Y](#mw%5F16ab20ae-3108-48b7-8051-f6d9a89008f1) = maxunpool([X](#mw%5F51461d2d-f6c4-4e9a-ad1f-f3f6dc2f245f),[indx](#mw%5Fa4826bb9-3ed5-4c02-bfc3-93170f8ee7f8),[outputSize](#mw%5F0dff3a95-7e20-478b-88f3-110653a973be),'DataFormat',[FMT](#mw%5Fb59913e2-8947-426c-8038-cf9caa9aeeb6%5Fsep%5Fmw%5F30d6528f-469b-47fb-a774-e80032eca842)) also specifies the dimension format FMT when X is not a formatted dlarray. The output Y is an unformatteddlarray with the same dimension order as X.

Examples

collapse all

Unpool 2-D Maximum Pooled Data

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.

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.

View the data size.

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.

Unpool 1-D Maximum Pooled Data

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.

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.

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.

Input Arguments

collapse all

X — Input data

dlarray

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

indx — Indices of maximum values

dlarray

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

Use the indices output of the maxpool function as the indx input tomaxunpool.

outputSize — Size of output feature map

numeric array

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

Use the size output of the maxpool function as the outputSize input tomaxunpool.

FMT — Description of data dimensions

character vector | string scalar

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:

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" once each, at most. 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

Y — Unpooled data

dlarray

Unpooled data, returned as a dlarray. The outputY has the same underlying data type as the inputX.

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:

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

GPU Arrays

Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.

The maxunpool function supports GPU array input with these usage notes and limitations:

For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2019b