FlattenLayer
represents a net layer that flattens any input array into a vector.
FlattenLayer[n]
represents a net layer that flattens its input to level n.
FlattenLayer[{{s11,s12,…},{s21,s22,…},…}]
represents a net layer that flattens its input by combining all levels sij to make each level i in the result.
Details and Options
- FlattenLayer is typically used inside NetChain, NetGraph, etc. to transform higher-rank arrays into vectors.
- In FlattenLayer[n], n can be one of the following:
-
i flatten the first i+1 dimensions together -i flatten the last i+1 dimensions together Infinity flatten all dimensions - FlattenLayer[] is equivalent to FlattenLayer[Infinity].
- FlattenLayer exposes the following ports for use in NetGraph etc.:
-
"Input" an array of arbitrary rank "Output" an array - FlattenLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,…}, use FlattenLayer["Input"->{n1,n2,…}].
- FlattenLayer[…][input] explicitly computes the output from applying the layer to input.
- FlattenLayer[…][{input1,input2,…}] explicitly computes outputs for each of the inputi.
- When given a NumericArray as input, the output will be a NumericArray.
- Options[FlattenLayer] gives the list of default options to construct the layer. Options[FlattenLayer[…]] gives the list of default options to evaluate the layer on some data.
- Information[FlattenLayer[…]] gives a report about the layer.
- Information[FlattenLayer[…],prop] gives the value of the property prop of FlattenLayer[…]. Possible properties are the same as for NetGraph.
Examples
open allclose allBasic Examples (2)
Create a FlattenLayer:
Create a FlattenLayer with specified input dimensions:
Scope (4)
Create a FlattenLayer that flattens the first two dimensions of the input, preserving the other dimensions:
Create a FlattenLayer that flattens the first three dimensions of its input together, and apply it to a 2×3×4×5 array:
Create and apply a FlattenLayer that flattens the last three dimensions together:
Create and apply a layer that flattens all the dimensions together:
Create a FlattenLayer that flattens levels 2 and 3 into the first level of the resulting array:
Create a FlattenLayer with specified input dimensions:
Properties & Relations (3)
FlattenLayer[] behaves like Flatten:
FlattenLayer[n] computes:
Flatten the first two dimensions:
Flatten the last two dimensions:
FlattenLayer[n] is equivalent to a ReshapeLayer[dims], where the dims depend on n and the dimensions of the input to FlattenLayer. Create a rank-3 array:
Apply a particular FlattenLayer:
Apply an equivalent ReshapeLayer:
Possible Issues (1)
FlattenLayer cannot accept symbolic inputs:
Text
Wolfram Research (2016), FlattenLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/FlattenLayer.html (updated 2021).
CMS
Wolfram Language. 2016. "FlattenLayer." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/FlattenLayer.html.
APA
Wolfram Language. (2016). FlattenLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FlattenLayer.html