FlattenLayer

FlattenLayer[]

represents a net layer that flattens any input tensor into a vector.

FlattenLayer[n]

represents a net layer that flattens its input to level n.

Details and Options

  • FlattenLayer[] is equivalent to FlattenLayer[Infinity].
  • FlattenLayer[][input] explicitly computes the output from applying the layer to input.
  • FlattenLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • In FlattenLayer[n], n can be one of the following:
  • nflatten the first n+1 dimensions together
    -nflatten the last n+1 dimensions together
    Infinityflatten all dimensions
  • FlattenLayer exposes the following ports for use in NetGraph etc.:
  • "Input"a tensor of arbitrary rank
    "Output"a tensor
  • FlattenLayer is typically used inside NetChain, NetGraph, etc. to transform higher-rank tensors into vectors.
  • 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,}].

Examples

open allclose all

Basic Examples  (2)

Create a FlattenLayer:

In[1]:=
Click for copyable input
Out[1]=

Create a FlattenLayer with specified input dimensions:

In[1]:=
Click for copyable input
Out[1]=

Apply the layer to a matrix:

In[2]:=
Click for copyable input
Out[2]=

Scope  (3)

Properties & Relations  (4)

Possible Issues  (2)

See Also

ReshapeLayer  ReplicateLayer  TransposeLayer  PartLayer  NetChain  NetGraph  Flatten

Introduced in 2016
(11.0)
| Updated in 2017
(11.1)