3-D average pooling layer
A 3-D average pooling layer performs down-sampling by dividing three-dimensional input into cuboidal pooling regions and computing the average values of each region.
creates an average pooling layer and sets the layer
= averagePooling3dLayer(poolSize
)PoolSize
property.
sets the optional layer
= averagePooling3dLayer(poolSize
,Name,Value
)Stride
and Name
properties
using name-value pairs. To specify input padding, use the 'Padding'
name-value pair argument. For example,
averagePooling3dLayer(2,'Stride',2)
creates a 3-D average pooling
layer with pool size [2 2 2]
and stride [2 2 2]
. You
can specify multiple name-value pairs. Enclose each property name in single quotes.
Use comma-separated name-value pair arguments to specify the size of the zero padding
to add along the edges of the layer input or to set the Stride
and Name
properties.
Enclose names in single quotes.
averagePooling3dLayer(2,'Stride',2)
creates a 3-D average
pooling layer with pool size [2 2 2]
and stride [2 2
2]
.'Padding'
— Input edge padding0
(default) | array of nonnegative integers | 'same'
Input edge padding, specified as the comma-separated pair consisting of
'Padding'
and one of these values:
'same'
— Add padding of size calculated by the software at
training or prediction time so that the output has the same size as the input
when the stride equals 1. If the stride is larger than 1, then the output size is
ceil(inputSize/stride)
, where inputSize
is the height,
width, or depth of the input and stride
is the stride in the corresponding
dimension. The software adds the same amount of padding to the top and bottom, to the left and
right, and to the front and back, if possible. If the padding in a given dimension has an odd
value, then the software adds the extra padding to the input as postpadding. In other words, the
software adds extra vertical padding to the bottom, extra horizontal padding to the right, and
extra depth padding to the back of the input.
Nonnegative integer p
— Add padding of size
p
to all the edges of the input.
Three-element vector [a b c]
of nonnegative integers — Add
padding of size a
to the top and bottom, padding of size
b
to the left and right, and padding of size
c
to the front and back of the input.
2-by-3 matrix [t l f;b r k]
of nonnegative integers — Add
padding of size t
to the top, b
to the
bottom, l
to the left, r
to the right,
f
to the front, and k
to the back of
the input. In other words, the top row specifies the prepadding and the second
row defines the postpadding in the three dimensions.
Example:
'Padding',1
adds one row of padding to the top and bottom, one column
of padding to the left and right, and one plane of padding to the front and back of the
input.
Example:
'Padding','same'
adds padding so that the output has the same size as
the input (if the stride equals 1).
PoolSize
— Dimensions of pooling regionsDimensions of the pooling regions, specified as a vector of three positive integers
[h w d]
, where h
is the height,
w
is the width, and d
is the depth. When
creating the layer, you can specify PoolSize
as a scalar to use the
same value for all three dimensions.
If the stride dimensions Stride
are less than the respective
pooling dimensions, then the pooling regions overlap.
The padding dimensions PaddingSize
must be less than the pooling
region dimensions PoolSize
.
Example:
[2 1 1]
specifies pooling regions of height 2, width 1, and depth
1.
Stride
— Step size for traversing input[1 1 1]
(default) | vector of three positive integersStep size for traversing the input in three dimensions, specified as a vector
[a b c]
of three positive integers, where a
is
the vertical step size, b
is the horizontal step size, and
c
is the step size along the depth direction. When creating the
layer, you can specify Stride
as a scalar to use the same value for
step sizes in all three directions.
If the stride dimensions Stride
are less than the respective
pooling dimensions, then the pooling regions overlap.
The padding dimensions PaddingSize
must be less than the pooling
region dimensions PoolSize
.
Example:
[2 3 1]
specifies a vertical step size of 2, a horizontal step size
of 3, and a step size along the depth of 1.
PaddingSize
— Size of padding[0 0 0;0 0 0]
(default) | 2-by-3 matrix of nonnegative integersSize of padding to apply to input borders, specified as 2-by-3 matrix
[t l f;b r k]
of nonnegative
integers, where t
and b
are the padding applied to the top and bottom in the vertical
direction, l
and r
are the
padding applied to the left and right in the horizontal
direction, and f
and k
are
the padding applied to the front and back along the depth. In
other words, the top row specifies the prepadding and the second
row defines the postpadding in the three dimensions.
When you create a layer, use the 'Padding'
name-value pair argument to specify the padding size.
Example:
[1 2 4;1 2 4]
adds one row of padding to the
top and bottom, two columns of padding to the left and right,
and four planes of padding to the front and back of the
input.
PaddingMode
— Method to determine padding size'manual'
(default) | 'same'
Method to determine padding size, specified as 'manual'
or
'same'
.
The software automatically sets the value of PaddingMode
based on the 'Padding' value you specify when creating a layer.
If you set the 'Padding'
option to a scalar or a vector
of nonnegative integers, then the software automatically sets PaddingMode
to
'manual'
.
If you set the 'Padding'
option to
'same'
, then the software automatically sets
PaddingMode
to
'same'
and calculates the size of the padding at
training time so that the output has the same size as the input when the
stride equals 1. If the stride is larger than 1, then the output size is
ceil(inputSize/stride)
, where inputSize
is the height,
width, or depth of the input and stride
is the stride in the corresponding
dimension. The software adds the same amount of padding to the top and bottom, to the left and
right, and to the front and back, if possible. If the padding in a given dimension has an odd
value, then the software adds the extra padding to the input as postpadding. In other words, the
software adds extra vertical padding to the bottom, extra horizontal padding to the right, and
extra depth padding to the back of the input.
PaddingValue
— Value used to pad input0
(default) | 'mean'
Value used to pad input, specified as 0
or 'mean'
.
When you use the 'Padding'
option to add padding to the input, the value of the padding applied can be one of the following:
0
— Input is padded with zeros at the positions specified by the 'Padding'
option. The padded areas are included in the calculation of the average value of the pooling regions along the edges.
'mean'
— Input is padded with the mean of the pooling region at the positions specified by the 'Padding'
option. The padded areas are effectively excluded from the calculation of the average value of each pooling region.
Example: 'PaddingValue','mean'
Name
— Layer name''
(default) | character vector | string scalar
Layer name, specified as a character vector or a string scalar.
To include a layer in a layer graph, you must specify a nonempty unique layer name. If you train
a series network with the layer and Name
is set to ''
,
then the software automatically assigns a name to the layer at training time.
Data Types: char
| string
NumInputs
— Number of inputsNumber of inputs of the layer. This layer accepts a single input only.
Data Types: double
InputNames
— Input names{'in'}
(default)Input names of the layer. This layer accepts a single input only.
Data Types: cell
NumOutputs
— Number of outputsNumber of outputs of the layer. This layer has a single output only.
Data Types: double
OutputNames
— Output names{'out'}
(default)Output names of the layer. This layer has a single output only.
Data Types: cell
Create a 3-D average pooling layer with nonoverlapping pooling regions that downsamples by a factor of 2.
layer = averagePooling3dLayer(2,'Stride',2)
layer = AveragePooling3DLayer with properties: Name: '' Hyperparameters PoolSize: [2 2 2] Stride: [2 2 2] PaddingMode: 'manual' PaddingSize: [2x3 double] PaddingValue: 0
Include a 3-D average pooling layer in a Layer
array.
layers = [ ... image3dInputLayer([28 28 28 3]) convolution3dLayer(5,20) reluLayer averagePooling3dLayer(2,'Stride',2) fullyConnectedLayer(10) softmaxLayer classificationLayer]
layers = 7x1 Layer array with layers: 1 '' 3-D Image Input 28x28x28x3 images with 'zerocenter' normalization 2 '' Convolution 20 5x5x5 convolutions with stride [1 1 1] and padding [0 0 0; 0 0 0] 3 '' ReLU ReLU 4 '' Average 3D Pooling 2x2x2 average pooling with stride [2 2 2] and padding [0 0 0; 0 0 0] 5 '' Fully Connected 10 fully connected layer 6 '' Softmax softmax 7 '' Classification Output crossentropyex
Create a 3-D average pooling layer with overlapping pooling regions and padding for the top and bottom of the input.
layer = averagePooling3dLayer([3 2 2],'Stride',2,'Padding',[1 0 0])
layer = AveragePooling3DLayer with properties: Name: '' Hyperparameters PoolSize: [3 2 2] Stride: [2 2 2] PaddingMode: 'manual' PaddingSize: [2x3 double] PaddingValue: 0
This layer creates pooling regions of size 3-by-2-by-2 and takes the average of the twelve elements in each region. The stride is 2 in all dimensions. The pooling regions overlap because there are stride dimensions Stride
that are less than the respective pooling dimensions PoolSize
.
A 3-D average pooling layer extends the functionality of an average
pooling layer to a third dimension, depth. An average pooling layer performs down-sampling
by dividing the input into rectangular or cuboidal pooling regions, and computing the
average of each region. To learn more, see the definition of average pooling layer
on the averagePooling2dLayer
reference page.
averagePooling2dLayer
| convolution3dLayer
| maxPooling3dLayer
You have a modified version of this example. Do you want to open this example with your edits?