ExtractLayer

ExtractLayer[]

represents a net layer that takes an array and a position specification as inputs and extracts the specified parts from the array.

Details and Options

  • ExtractLayer exposes the following ports for use in NetGraph etc.:
  • "Input"input array
    "Position"integer array of part specifications
    "Output"output array
  • ExtractLayer is typically used inside NetChain, NetGraph, etc.
  • ExtractLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,} and {m1,m2,}, use ExtractLayer["Input"->{n1,n2,},"Position"->{m1,m2,}].
  • ExtractLayer["Port"shape] allows the shape of the "Input" or "Position" port to be specified. Possible forms of shape are:
  • na vector of length n
    {n1,n2,}an array of dimensions n1×n2×
    {"Varying",n2,n3,}an array whose first dimension is variable and whose remaining dimensions are n2×n3×
    NetEncoder[]an encoder
  • The shape of the "Position" port can also be set to "Integer" to specify a single integer.
  • The input to the port "Position" is an arbitrary array of part specifications. Given an input of dimensions {n1,n2,,nd } and a position specification of dimensions {m1,m2,,mp,s}, the output will have dimensions {m1,m2,,mp,ns+1,,nd}.
  • The last dimension of the position specification s is used to specify elements of the input, and so it cannot be greater than the input rank d. In the case of s=d, the output dimensions will just be {m1,m2,,mp}.
  • ExtractLayer[][<|"Input"input,"Position"position|>] explicitly computes the output from applying the layer to input and position.
  • ExtractLayer[][<|"Input"{input1,input2,},"Input"{pos1,pos2,}|> explicitly computes output for each of the inputi and the posi.
  • Negative integers in the position specification are counted from the last element progressing backward.
  • When given a NumericArray as input, the output will be a NumericArray.
  • Options[ExtractLayer] gives the list of default options to construct the layer. Options[ExtractLayer[]] gives the list of default options to evaluate the layer on some data.
  • Information[ExtractLayer[]] gives a report about the layer.
  • Information[ExtractLayer[],prop] gives the value of the property prop of ExtractLayer[]. Possible properties are the same as for NetGraph.

Examples

open allclose all

Basic Examples  (1)

Create an ExtractLayer:

Apply the layer to a vector and a part specification:

Scope  (2)

Arguments  (1)

Create an ExtractLayer:

Specify a list of parts:

Ports  (1)

Create an ExtractLayer and specify the shape of its "Input" and "Position" ports:

Apply the layer to an input-position pair:

Apply the layer to a batch of input-position pairs:

Properties & Relations  (2)

ExtractLayer performs the same computation as Extract:

ExtractLayer selects parts of an array based on the current specification, while PartLayer has a fixed-part specification:

PartLayer only supports a single-part specification and not an arbitrary array of those, but accepts Span to extract chunks of the input:

Possible Issues  (3)

The last dimension of the position specification selects the desired parts of the input; hence its size must not exceed the input rank:

If the "Position" specification has a rank of 1, its size cannot be variable:

An unspecified ExtractLayer will always assume it is being evaluated on a single example and not on a batch. In the following, the arrays data and pos will be interpreted as a single 2×3 input array and a 2×1 part specification, respectively:

In order to have them interpreted as a batch of two lists of length 3 and 1, respectively, explicit shapes must be specified prior to evaluation:

Wolfram Research (2019), ExtractLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ExtractLayer.html.

Text

Wolfram Research (2019), ExtractLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ExtractLayer.html.

CMS

Wolfram Language. 2019. "ExtractLayer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExtractLayer.html.

APA

Wolfram Language. (2019). ExtractLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExtractLayer.html

BibTeX

@misc{reference.wolfram_2024_extractlayer, author="Wolfram Research", title="{ExtractLayer}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/ExtractLayer.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_extractlayer, organization={Wolfram Research}, title={ExtractLayer}, year={2019}, url={https://reference.wolfram.com/language/ref/ExtractLayer.html}, note=[Accessed: 22-November-2024 ]}