NetReplacePart

NetReplacePart[layer,"array"value]

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

NetReplacePart[net,"port"type]

returns a new layer or network 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,lspeclayer]

returns a new NetChain or NetGraph in which the layer identified by lspec has been replaced.

NetReplacePart[net,NetSharedArray[name]value]

sets a shared array within a network or layer to a specified value.

NetReplacePart[coder,"param"value]

returns a new NetEncoder[] or NetDecoder[] in which a parameter has been replaced.

NetReplacePart[net,{lspec,pspec}value]

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

NetReplacePart[net,{spec1val1,spec2val2,}]

makes multiple simultaneous replacements.

Details

  • NetReplacePart can replace layer parameters, layer arrays, layers, encoders, decoders, encoder parameters, decoder parameters, input array sizes and output array sizes.
  • 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,}an array of dimensions n1×n2×
    "Varying"a variable-length vector
    {"Varying",n2,n3,}an array whose first dimension is variable and remaining dimensions are n2×n3×
    NetEncoder[]an encoder (for input ports)
    NetDecoder[]a decoder (for output ports)
  • When specifying the size n of an array dimension, n can be a positive integer, or Automatic to indicate it should be inferred.
  • If an input port is replaced, any NetDecoder present on an output port will be removed unless a specific replacement value is also given for the output port.
  • When a specific layer is replaced, the shapes of the inputs and outputs of the original layer must match those of the layer it is replaced with.
  • An encoder or decoder can be removed from a port by specifying the value None.

Examples

open all close all

Basic Examples  (1)

Obtain a trained model:

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

Obtain a new model in which the input NetEncoder has been removed:

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

Obtain a new model in which the first activation layer has been replaced:

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

Obtain a new model in which the first convolution biases have been randomized:

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

Scope  (10)

Properties & Relations  (1)

Introduced in 2016
(11.0)
|
Updated in 2019
(12.0)