extracts the value of a parameter for the specified net layer.


extracts the layer identified by lspec from within the NetGraph or NetChain object net.


extracts the value of the parameter param from the layer identified by lspec in net.


extracts the value of a shared array within a network or layer.


extracts the value of a parameter for the specified NetEncoder or NetDecoder.


extracts a set of elements, where each speci is a list.


  • NetExtract supports the layer specification All to indicate that an association or list should be returned, giving all the layers within a NetGraph or NetChain, respectively.
  • The layer specification can be an integer indicating the n^(th) layer or a string indicating a named layer.
  • Parameter specifications can be the names of any of the arrays or options contained within a layer.
  • NetExtract returns Automatic if a learned parameter has not yet been initialized, or an unlearned parameter has not yet been inferred.
  • NetExtract[net,{spec1,spec2,}] is equivalent to net[[spec1,spec2,]] when speci are not lists.
  • For NetChain, NetGraph, NetEncoder and NetDecoder objects, Normal[net] is equivalent to NetExtract[net,All].


open allclose all

Basic Examples  (4)

Create a randomly initialized layer:

Extract the weight matrix from the layer:

Create a NetChain:

Extract the third layer:

Create an operator containing a net:

Extract the net from inside the operator:

Create a NetEncoder:

Extract the type of encoder:

Extract the output dimensions of the encoder:

Extract the color space of the encoder:

Scope  (6)

Create a NetChain with named layers:

Extract the first layer:

Extract the last layer:

Extract a named layer:

Extract the function used in the elementwise layer:

Extract several layers:

Extract all layers:

Create an initialized NetChain:

Extract the weights from a specific layer:

Extract the weights from all layers:

Create a NetGraph object with named layers:

Extract a named layer:

Extract all the layers:

Create a layer with specific input dimensions:

Extract the input dimensions:

Extract the output dimensions:

Create a layer with an attached encoder:

Extract the input encoder:

Extract a parameter of the input encoder:

Extract the type and output dimensions of the input encoder:

Extract the value of all shared arrays in a network:

In this example, NetSharedArray["Weights"] corresponds to the value of the weights in all layers:

Properties & Relations  (1)

The part specifications supported by NetExtract are identical to those used by NetReplacePart.

Possible Issues  (1)

Create a ConvolutionLayer:

Attempting to extract the weights of this uninitialized layer returns Automatic:

Known parameters can be extracted:

Introduced in 2016
Updated in 2020