FlattenLayer

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.

Details and Options

Examples

open allclose all

Basic Examples  (2)

Create a FlattenLayer:

Create a FlattenLayer with specified input dimensions:

Apply the layer to a matrix:

Scope  (3)

Create a FlattenLayer that flattens the first two dimensions of the input, preserving the other dimensions:

Apply the layer to an input:

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 with specified input dimensions:

Thread the layer across a batch of inputs:

Properties & Relations  (4)

FlattenLayer[] behaves like Flatten:

FlattenLayer[n] computes:

Create a rank-3 array:

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:

In previous versions of the Wolfram Language, FlattenLayer was often used to convert a higher-rank array into a vector suitable for DotPlusLayer, the previous version of LinearLayer:

Unlike DotPlusLayer, LinearLayer can take arbitrary array inputs, and so the FlattenLayer is unnecessary:

Possible Issues  (2)

To prevent inadvertent errors, FlattenLayer[n] requires the input to have rank greater than n:

In contrast, Flatten[input,n] works for any n:

FlattenLayer[Infinity] accepts arrays of any rank:

FlattenLayer cannot accept symbolic inputs:

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