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


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


attaches a NetEncoder[] to a specified input port.


attaches a NetDecoder[] to a specified output port.


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


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


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


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


makes multiple simultaneous replacements.


  • 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.


open all close all

Basic Examples  (1)

Obtain a trained model:

Click for copyable input

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

Click for copyable input

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

Click for copyable input

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

Click for copyable input

Scope  (10)

Properties & Relations  (1)

Introduced in 2016
Updated in 2019