Contenido principal

Reshape Layer

R2026b

Reshape layer

Since R2026b

  • Reshape Layer block

Libraries:
Deep Learning Toolbox / Deep Learning Layers / Utility Layers

Description

The Reshape Layer block reshapes layer input data to the specified output size.

The exportNetworkToSimulink function generates this block to represent a reshapeLayer object.

Examples

expand all

Export a trained neural network to Simulink® as layer blocks.

For most workflows, you do not need to create neural networks in Simulink. Instead, import or train a neural network in MATLAB® and export it to Simulink.

Suppose that you have a trained neural network net specified as a dlnetwork object. Export the network to Simulink using the exportNetworkToSimulink function.

mdlInfo = exportNetworkToSimulink(net)

Neural network as subsystem in Simulink. The subsystem has the name "my_model". It has one input with the name "data" and one output with the name "prob_flatten_out".

The exported Simulink model represents the neural network as a subsystem. To view the layer blocks, open the subsystem. This example shows the first few blocks of a neural network.

Neural network as layer blocks in Simulink. The subsystem has one input with the name data. The data input is connected to four layer blocks in series. The layer blocks in order are Zerocenter 2D, Convolution 2D, ReLU, and Max Pooling 2D layer blocks. There are more blocks in the model which have been cropped from the screenshot.

To view and edit the layer block parameters, open the corresponding layer block mask. This example shows the parameters for the ReLU block.

Block Parameters dialog for the ReLU block.

Using the layer block parameters, you can configure aspects like data types and execution options like sample times.

Ports

Input

expand all

Input data to reshape.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Complex Number Support: Yes

Output

expand all

Reshaped output data.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Complex Number Support: Yes

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Main

Size of the reshaped output, specified as an array of positive scalars.

Each element indicates the output size of the corresponding dimension given by the Operation dimension parameter. For example, if Operation dimension is spatial-channel, then the elements of Output size indicate the sizes of the spatial and channel dimensions of the layer output.

Programmatic Use

Block Parameter: OutputSize
Type: character vector
Values: '[1,1]' | '<array>'
Default: '[1,1]'

Dimension along which to reshape the data, specified as one of these values:

  • all — Reshape data by reordering the elements in all dimensions.

  • spatial-channel — Reshape data by reordering the elements in the spatial and channel dimensions only. Use this option when you have image or image-sequence data with varying batch sizes or sequence lengths.

  • A vector of positive integers — Reshape data along the specified dimensions. The vector must specify a contiguous range of dimensions in the form [m:n]. For example, [2,3] reshapes the data along the second and third dimensions.

Dependencies

Setting this parameter to spatial-channel enables the Data format parameter.

Setting this parameter to a vector of positive integers enables the Input size parameter.

Programmatic Use

Block Parameter: OperationDimension
Type: character vector
Values: 'all' | 'spatial-channel' | '[m:n]'
Default: 'all'

Data format for the input data. The options use the same notation as the fmt argument of the dlarray object, except that these data formats do not include the batch (B) or unspecified (U) dimension.

The data itself can include additional batch or unspecified dimension of size 1. To reshape data with a batch size greater than one, set Operation dimension to all or to a vector of positive integers.

Dependencies

To enable this parameter, set Operation dimension to spatial-channel.

Programmatic Use

Block Parameter: DataFormat
Type: character vector
Values: 'SSC' | 'C' | 'CT' | 'SC' | 'SSSC'
Default: 'SSC'

Size of the input data to the block, specified as an array of positive scalars. To determine the activations of the layer that precedes a reshapeLayer object, you can use the analyzeNetwork function.

Dependencies

To enable this parameter, set Operation dimension to a vector of positive integers.

Programmatic Use

Block Parameter: InputSize
Type: character vector
Values: '1' | '<array>'
Default: '1'

Execution

Specify the discrete interval between sample time hits or specify another type of sample time, such as continuous (0) or inherited (-1). For more options, see Types of Sample Time (Simulink).

By default, the block inherits its sample time based on the context of the block within the model.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

Parameter: SampleTime
Data Types: char
Values: '-1' | scalar
Default: '-1'

Version History

Introduced in R2026b