Main Content

resize3dLayer

3-D resize layer

Since R2020b

Description

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

Creation

Description

layer = resize3dLayer("Scale",scale) creates a 3-D resize layer and sets the Scale property as the scale factor specified by scale.

example

layer = resize3dLayer("OutputSize",outputSize) creates a 3-D resize layer and sets the OutputSize property with the height, width, and depth specified by outputSize.

example

layer = resize3dLayer("EnableReferenceInput",tf) creates a 3-D resize layer and sets the EnableReferenceInput property with the boolean specified by tf. When you specify the value as true, 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 = resize3dLayer(___,Name,Value) also sets the optional Method, GeometricTransformMode, NearestRoundingMode, and Name properties using name-value arguments. You can specify multiple name-value arguments.

Example: layer = resize3dLayer("OutputSize",[128 128 36],"Method","trilinear") creates a 3-D resize layer that resizes input to 128-by-128-by-36 pixels using trilinear interpolation

example

Properties

expand all

Resize

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

Output size of resized input, specified as a 3-element row vector of positive integers of the form [nrows ncols nplanes]. You can specify two elements as NaN, in which case the layer computes the values automatically to preserve the aspect ratio of the input.

Add reference feature map as input to the layer, specified as a numeric or logical 0 (false) or 1 (true). When you specify the value as true, the layer resizes the height, width, and depth of the input to match the height, width, and depth 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 using connectLayers (Deep Learning Toolbox) or disconnectLayers (Deep Learning Toolbox).

Interpolation method, specified as "nearest" for nearest neighbor interpolation or "trilinear" for trilinear 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® round function.

  • "floor" — use the same rounding behavior as the MATLAB floor function.

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

This property is valid when the Method property is "nearest".

Layer

Layer name, specified as a character vector or string scalar. For Layer array input, the trainnet (Deep Learning Toolbox) and dlnetwork (Deep Learning Toolbox) functions automatically assign names to layers with the name "".

The Resize3DLayer object stores this property as a character vector.

Data Types: char | string

Number of inputs of the layer, specified as 1 when the EnableReferenceInput property is false or 2 when the EnableReferenceInput property is true.

Data Types: double

Input names of the layer, specified as {'in'} when the EnableReferenceInput property is false or {'in','ref'} when the EnableReferenceInput property is true.

Data Types: cell

This property is read-only.

Number of outputs from the layer, returned as 1. This layer has a single output only.

Data Types: double

This property is read-only.

Output names, returned as {'out'}. This layer has a single output only.

Data Types: cell

Examples

collapse all

Create a 3-D resize layer. Specify a horizontal and vertical scale factor of 2 and a depthwise scale factor of 4.

layer = resize3dLayer('Scale',[2 2 4])
layer = 
  Resize3DLayer with properties:

                      Name: ''
                     Scale: [2 2 4]
                OutputSize: []
      EnableReferenceInput: 0
                    Method: 'nearest'
    GeometricTransformMode: 'half-pixel'
       NearestRoundingMode: 'round'

   Learnable Parameters
    No properties.

   State Parameters
    No properties.

Use properties method to see a list of all properties.

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

layer = resize3dLayer('OutputSize',[224 224 224],'Name','resize224')
layer = 
  Resize3DLayer with properties:

                      Name: 'resize224'
                     Scale: []
                OutputSize: [224 224 224]
      EnableReferenceInput: 0
                    Method: 'nearest'
    GeometricTransformMode: 'half-pixel'
       NearestRoundingMode: 'round'

   Learnable Parameters
    No properties.

   State Parameters
    No properties.

Use properties method to see a list of all properties.

Create a dlnetwork object.

net = dlnetwork;

Create an array of layers that includes a 3-D resize layer that accepts a reference input feature map. Add the layers to the network.

layers = [
    image3dInputLayer([32 32 32 3],Name="image")
    resize3dLayer(EnableReferenceInput=true,Name="resize")]
layers = 
  2x1 Layer array with layers:

     1   'image'    3-D Image Input   32x32x32x3 images with 'zerocenter' normalization
     2   'resize'   Resize            nnet.cnn.layer.Resize3DLayer
net = addLayers(net,layers);

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

net = connectLayers(net,"image","resize/ref");

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

layer = resize3dLayer('Scale',0.5,'Method','trilinear','Name','rescale0.5')
layer = 
  Resize3DLayer with properties:

                      Name: 'rescale0.5'
                     Scale: [0.5000 0.5000 0.5000]
                OutputSize: []
      EnableReferenceInput: 0
                    Method: 'trilinear'
    GeometricTransformMode: 'half-pixel'
       NearestRoundingMode: 'round'

   Learnable Parameters
    No properties.

   State Parameters
    No properties.

Use properties method to see a list of all properties.

References

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

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

Version History

Introduced in R2020b

expand all

See Also

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

Topics