NetReplacePart

NetReplacePart[layer,"array"value]

replaces an array within a layer, returning a new layer.

NetReplacePart[layer,"port"type]

returns a new layer in which an input or output port has the specified type.

NetReplacePart[net,"input"encoder]

attaches a NetEncoder[] to a specified input port.

NetReplacePart[net,"output"decoder]

attaches a NetDecoder[] to a specified output port.

NetReplacePart[net,{lspec,pspec}value]

makes a replacement of a part pspec of a layer lspec within a NetGraph or NetChain.

NetReplacePart[net,{spec1val1,spec2val2,}]

makes multiple simultaneous replacements.

Details

  • The part specifications supported by NetReplacePart are identical to those used by NetExtract.
  • When replacing an array within a layer, the new value must have the same dimensions as the original array.
  • When replacing an input or an output in order to fully specify a partially specified network, any of the following values can be used to specify the type of the port:
  • "Real"a single real number
    "Integer"a single integer
    na vector of length n
    {n1,n2,}a tensor of dimensions n1×n2×
    "Varying"a variable-length vector
    {"Varying",n2,n3,}a variable-length sequence of tensors of dimensions n2×n3×
    NetEncoder[]an encoder (for input ports)
    NetDecoder[]a decoder (for output ports)
    "type"NetEncoder["type"] or NetDecoder["type"]
    {n,coder}an encoder or decoder mapped over a sequence of length n
  • When specifying the size n of a tensor dimension, n can be a positive integer, or Automatic to indicate it should be inferred.
  • An encoder or decoder can be removed from a port by specifying the value None.
  • Entire layers within a NetChain or NetGraph cannot be replaced.

Examples

open allclose all

Basic Examples  (2)

Create a linear layer with no weight matrix specified:

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

Insert specific weights and biases:

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

Evaluate the layer on an input:

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

Create a layer without an input encoder:

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

Attach a "Class" encoder to the input of the layer, which embeds the classes as {1,0} and {0,1}:

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

The resulting layer can now take the values True and False as inputs:

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=

Scope  (3)

See Also

NetExtract  NetEncoder  NetDecoder  NetChain  NetGraph  ReplacePart

Introduced in 2017
(11.1)