Main Content

resize2dLayer

2-D resize layer

Description

A 2-D resize layer resizes 2-D input by a scale factor, to a specified height and width, or to the size of a reference input feature map.Use of this layer requires Deep Learning Toolbox™.

Creation

Description

example

layer = resize2dLayer('Scale',scale)creates a 2-D resize layer and sets theScaleproperty as the scale factor specified byscale.

example

层= resize2dLayer(“输出Size',outputSize)creates a 2-D resize layer and sets theOutputSizeproperty with the height and width specified byoutputSize.

example

layer = resize2dLayer('EnableReferenceInput',tf)creates a 2-D resize layer and sets theEnableReferenceInputproperty with the boolean specified bytf. When you specify the value astrue, the layer adds an additional input that accepts a reference feature map and resizes the input to the size of the reference feature map.

example

layer = resize2dLayer(___,Name,Value)sets the optionalMethod,GeometricTransformMode,NearestRoundingMode, andNameproperties using name-value pair arguments. You can specify multiple name-value pair arguments. Enclose each property name in single quotes.

Example:层= resize2dLayer(“输出Size',[128 128],'Method','bilinear')creates a 2-D resize layer that resizes input to 128-by-128 pixels using bilinear interpolation

Properties

expand all

Resize

Scale factor to resize input, specified as 2-element row vector of positive numbers. The scale factors are for the row and column dimensions, respectively. When creating the layer, you can specifyScaleas a scalar to use the same value for both dimensions.

Output size of resized input, specified as a 2-element row vector of positive integers of the form [nrowsncols]. You can specify one element as NaN, in which case the layer computes the value automatically to preserve the aspect ratio of the input.

Add reference feature map as input to the layer, specified asa numeric or logical0(false) or1(true). When you specify the value astrue, the layer resizes the height and width of the input to match the height and width of the reference feature map. The resizing operation does not change the number of channels of the input.

When you enable a reference feature map, the inputs to the layer have the names'in1'and'ref', where'ref'is the name of the reference feature map. Use the input names when connecting or disconnecting the layer by usingconnectLayers(Deep Learning Toolbox)ordisconnectLayers(Deep Learning Toolbox).

插值法, specified as'nearest'for nearest neighbor interpolation or'bilinear'for bilinear interpolation.

Geometric transformation mode to map points from input space to output space, specified as'half-pixel'or'asymmetric'.

Rounding mode for nearest neighbor interpolation, specified as one of the following.

  • 'round'— use the same rounding behavior as the MATLAB®roundfunction.

  • 'floor'— use the same rounding behavior as the MATLABfloorfunction.

  • 'onnx-10'— reproduce the resizing behavior of the ONNX™ (Open Neural Network Exchange) opset 10 Resize operator.

This property is valid when theMethodproperty is'nearest'.

Layer

Layer name, specified as a character vector or a string scalar. ForLayerarray input, thetrainNetwork,assembleNetwork,layerGraph, anddlnetworkfunctions automatically assign names to layers with name''.

Data Types:char|string

Number of inputs of the layer, specified as1when theEnableReferenceInputproperty isfalseor2when theEnableReferenceInputproperty istrue.

Data Types:double

Input names of the layer, specified as{'in'}when theEnableReferenceInputproperty isfalseor{“在”,“ref”}when theEnableReferenceInputproperty istrue.

Data Types:cell

This property is read-only.

Number of outputs of the layer. This layer has a single output only.

Data Types:double

This property is read-only.

Output names of the layer. This layer has a single output only.

Data Types:cell

Examples

collapse all

Create a 2-D resize layer with a horizontal scale factor of 2 and a vertical scale factor of 4.

layer = resize2dLayer('Scale',[2 4])
layer = Resize2DLayer with properties: Name: '' Scale: [2 4] OutputSize: [] EnableReferenceInput: 0 Method: 'nearest' GeometricTransformMode: 'half-pixel' NearestRoundingMode: 'round' Learnable Parameters No properties. State Parameters No properties. Show all properties

Create a 2-D resize layer named 'resize224' with an output size of [224 224].

layer = resize2dLayer('OutputSize',[224 224],'Name','resize224')
layer = Resize2DLayer with properties: Name: 'resize224' Scale: [] OutputSize: [224 224] EnableReferenceInput: 0 Method: 'nearest' GeometricTransformMode: 'half-pixel' NearestRoundingMode: 'round' Learnable Parameters No properties. State Parameters No properties. Show all properties

Create an array of layers that includes a 2-D resize layer that accepts a reference input feature map.

layers = [ imageInputLayer([32 32 3],'Name','image') resize2dLayer('EnableReferenceInput',true,'Name','resize')]
layers = 2x1 Layer array with layers: 1 'image' Image Input 32x32x3 images with 'zerocenter' normalization 2 'resize' Resize nnet.cnn.layer.Resize2DLayer

Create alayerGraph. The first input of the 2-D resize layer is automatically connected to the output of the image input layer.

lgraph = layerGraph(layers);

Connect the'ref'input of the 2-D resize layer to the output of a layer that provides a reference feature map by using theconnectLayersfunction. This example shows a trivial connection in which the'ref'input is also connected to the output of the image input layer.

lgraph = connectLayers(lgraph,'image','resize/ref');

Create a 2-D resize layer named 'rescale0.5' with a uniform scale factor of 0.5. Specify the interpolation method as bilinear interpolation.

layer = resize2dLayer('Scale',0.5,'Method','bilinear','Name','rescale0.5')
layer = Resize2DLayer with properties: Name: 'rescale0.5' Scale: [0.5000 0.5000] OutputSize: [] EnableReferenceInput: 0 Method: 'bilinear' GeometricTransformMode: 'half-pixel' NearestRoundingMode: 'round' Learnable Parameters No properties. State Parameters No properties. Show all properties

References

[1]Open Neural Network Exchange.https://github.com/onnx/.

[2]ONNX.https://onnx.ai/.

Extended Capabilities

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2020b

See Also

||(Deep Learning Toolbox)|(Deep Learning Toolbox)|(Deep Learning Toolbox)

Topics