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[][<|"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.
  • When given a NumericArray as input, the output will be a NumericArray.
  • 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}.
  • Negative integers in the position specification are counted from the last element progressing backward.

Examples

open all close all

Basic Examples  (2)

Create an ExtractLayer:

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

Create an ExtractLayer:

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

Apply the layer to a vector and a part specification:

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

Scope  (2)

Properties & Relations  (2)

Possible Issues  (3)

Introduced in 2019
(12.0)