AggregationLayer

AggregationLayer[f]

represents a layer that aggregates an array of arbitrary rank into a vector, using the function f.

AggregationLayer[f,n]

aggregates an array at level n.

AggregationLayer[f,n1;;n2]

aggregates an array at levels n1 through n2.

AggregationLayer[f,{n1,n2,}]

aggregates an array at levels n1,n2,.

Details and Options

  • AggregationLayer is typically used inside NetChain, NetGraph, etc. as the final stage in a chain of convolutions, poolings, etc. to convert an array with spatial dimensions into a fixed-size vector representation.
  • AggregationLayer[f] operates on an array of dimensions {d1,,dn} to produce a vector of size d1, effectively mapping the function f over a list of flattened subarrays of size d2××dn.
  • AggregationLayer[f,{n1,,nk}] operates on a rank-m array of dimensions {d1,,dm} to produce an array of rank m-k, with dimensions Complement[{d1,,dm},{dn1,,dnk}].
  • Possible values for f are Mean, Min, Max, Total and Times.
  • AggregationLayer[f] is equivalent to AggregationLayer[f,2;;All].
  • AggregationLayer exposes the following ports for use in NetGraph etc.:
  • "Input"an array
    "Output"an array
  • When it cannot be inferred from other layers in a larger net, the option "Input"{d1,,dn} can be used to fix the input of AggregationLayer to be an array of dimensions {d1,,dn}.
  • AggregationLayer[][input] explicitly computes the output from applying the layer.
  • AggregationLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • When given a NumericArray as input, the output will be a NumericArray.
  • Options[AggregationLayer] gives the list of default options to construct the layer. Options[AggregationLayer[]] gives the list of default options to evaluate the layer on some data.
  • Information[AggregationLayer[]] gives a report about the layer.
  • Information[AggregationLayer[],prop] gives the value of the property prop of AggregationLayer[]. Possible properties are the same as for NetGraph.

Examples

open allclose all

Basic Examples  (2)

Create an AggregationLayer using Max as the aggregation function:

Create an AggregationLayer that sums the elements of each column of a matrix:

Apply the layer to an input:

Scope  (5)

Create an AggregationLayer that finds the maximum value of an array:

Apply the layer to an input:

This is equivalent to:

Create an AggregationLayer that aggregates over the first, third and fourth dimensions of an input array:

Apply the layer to an input:

Create an AggregationLayer with the input size specified:

Apply the layer to an input:

Thread the layer across a batch of inputs:

Apply an AggregationLayer to aggregate over all the pixels in an image, returning the mean values for each color channel:

Apply an AggregationLayer to aggregate across color channels, turning a color image into a grayscale one:

Apply an AggregationLayer to aggregate over a varying dimension:

Properties & Relations  (1)

AggregationLayer[f,{n1,,nk}] is equivalent to:

Possible Issues  (1)

AggregationLayer cannot accept symbolic inputs:

Introduced in 2017
 (11.1)
 |
Updated in 2017
 (11.2)
2018
 (11.3)
2020
 (12.1)