ReshapeLayer
ReshapeLayer[dims]
represents a net layer that reinterprets the input to be an array of dimensions dims.
Details and Options
- ReshapeLayer[…][input] explicitly computes the output from applying the layer to input.
- ReshapeLayer[…][{input1,input2,…}] explicitly computes outputs for each of the inputi.
- When given a NumericArray as input, the output will be a NumericArray.
- ReshapeLayer exposes the following ports for use in NetGraph etc.:
-
"Input" an array of arbitrary rank "Output" an array of dimension dims - In ReshapeLayer[dims], the following elements are allowed in the list dims:
-
n explicitly specify the size Inherited copy the size from the input Automatic infer the size from the size of the other dimensions All copy the remaining sizes from the input - Only one Automatic or one All is allowed in the list of dimensions.
- The total number of elements in the input array is equal to the total number of elements in the output array. The total number of elements in the input array is equal to the total number of elements in the output array.
- ReshapeLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,…}, use ReshapeLayer["Input"->{n1,n2,…}].
- Options[ReshapeLayer] gives the list of default options to construct the layer. Options[ReshapeLayer[…]] gives the list of default options to evaluate the layer on some data.
- Information[ReshapeLayer[…]] gives a report about the layer.
- Information[ReshapeLayer[…],prop] gives the value of the property prop of ReshapeLayer[…]. Possible properties are the same as for NetGraph.
Examples
open allclose allBasic Examples (3)
Create a ReshapeLayer that reshapes any input into a 2×3 matrix:
Create a ReshapeLayer that reshapes any input into a 2×3 matrix:
Apply the layer to a 4-dimensional array:
Create a ReshapeLayer that reshapes a length-1 vector into a single number:
Scope (5)
Create a ReshapeLayer that reshapes an input array of a specific size:
Create a ReshapeLayer that copies the size of the first dimension of its input:
Apply the layer to an array of dimensions 6×1×4:
Create a ReshapeLayer that copies the size of the first dimension of its input and infers the size of the fourth dimension from the others:
Apply the layer to an array of dimensions 6×4×4:
Create a ReshapeLayer the takes a 32×32 RGB image and returns a 96×32 grayscale image:
Create a ReshapeLayer that adds a dimension of size 1 on the deepest level of an array:
Properties & Relations (3)
FlattenLayer can be implemented using ReshapeLayer. Flatten the first two dimensions of a 2×3×3 array by reshaping it to the correct output dimensions:
The specifications Automatic and Inherited allow ReshapeLayer to recompute its output size when its input size is changed by NetReplacePart. Create a ReshapeLayer:
If the same ReshapeLayer was created with fixed specifications, resizing would lead to a failure:
For the case of integer dimension specifications, ReshapeLayer computes:
Possible Issues (2)
The total number of elements in the input must equal the total number in the output:
Only one Automatic is allowed in the dimension specification, as more than one would lead to ambiguities in the output size:
Interactive Examples (1)
Neat Examples (2)
Reshape a list into an array of depth 3 and use Image3D to visualize the result:
Text
Wolfram Research (2016), ReshapeLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ReshapeLayer.html (updated 2020).
CMS
Wolfram Language. 2016. "ReshapeLayer." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/ReshapeLayer.html.
APA
Wolfram Language. (2016). ReshapeLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReshapeLayer.html