WOLFRAM

NetExtract[layer,"param"]

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

NetExtract[net,lspec]

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

NetExtract[net,{lspec,"param"}]

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

NetExtract[net,NetArray[spec]]

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

NetExtract[coder,"param"]

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

NetExtract[,{spec1,spec2,}]

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

Details

  • NetExtract supports the level specification All to indicate that an association should be returned, giving all the layers within a NetGraph or NetChain, or all the properties of net layers, NetEncoder and NetDecoder.
  • 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 the speci are not lists.
  • For NetChain, NetGraph, NetEncoder, NetDecoder and layers, Normal[net] is equivalent to NetExtract[net,All].

Examples

open allclose all

Basic Examples  (4)Summary of the most common use cases

Create a randomly initialized layer:

Out[1]=1

Extract the weight matrix from the layer:

Out[2]=2

Create a NetChain:

Out[1]=1

Extract the third layer:

Out[2]=2

Create an operator containing a net:

Out[1]=1

Extract the net from inside the operator:

Out[2]=2

Create a NetEncoder:

Out[1]=1

Extract the type of encoder:

Out[2]=2

Extract the output dimensions of the encoder:

Out[3]=3

Extract the color space of the encoder:

Out[4]=4

Scope  (6)Survey of the scope of standard use cases

Create a NetChain with named layers:

Out[1]=1

Extract the first layer:

Out[2]=2

Extract the last layer:

Out[3]=3

Extract a named layer:

Out[4]=4

Extract the function used in the elementwise layer:

Out[5]=5

Extract several layers:

Out[6]=6

Extract all layers:

Out[7]=7

Create an initialized NetChain:

Out[1]=1

Extract the weights from a specific layer:

Out[2]=2

Extract the weights from all layers:

Out[3]=3

Create a NetGraph object with named layers:

Out[1]=1

Extract a named layer:

Out[2]=2

Extract all the layers:

Out[3]=3

Create a layer with specific input dimensions:

Out[1]=1

Extract the input dimensions:

Out[2]=2

Extract the output dimensions:

Out[3]=3

Create a layer with an attached encoder:

Out[1]=1

Extract the input encoder:

Out[2]=2

Extract a parameter of the input encoder:

Out[3]=3

Extract the type and output dimensions of the input encoder:

Out[4]=4

Extract the value of all shared arrays in a network:

Out[1]=1
Out[2]=2
Out[3]=3

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

Out[4]=4

Properties & Relations  (1)Properties of the function, and connections to other functions

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

Possible Issues  (1)Common pitfalls and unexpected behavior

Create a ConvolutionLayer:

Out[1]=1

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

Out[2]=2

Known parameters can be extracted:

Out[3]=3
Wolfram Research (2016), NetExtract, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExtract.html (updated 2020).
Wolfram Research (2016), NetExtract, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExtract.html (updated 2020).

Text

Wolfram Research (2016), NetExtract, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExtract.html (updated 2020).

Wolfram Research (2016), NetExtract, Wolfram Language function, https://reference.wolfram.com/language/ref/NetExtract.html (updated 2020).

CMS

Wolfram Language. 2016. "NetExtract." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetExtract.html.

Wolfram Language. 2016. "NetExtract." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetExtract.html.

APA

Wolfram Language. (2016). NetExtract. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetExtract.html

Wolfram Language. (2016). NetExtract. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetExtract.html

BibTeX

@misc{reference.wolfram_2025_netextract, author="Wolfram Research", title="{NetExtract}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetExtract.html}", note=[Accessed: 29-March-2025 ]}

@misc{reference.wolfram_2025_netextract, author="Wolfram Research", title="{NetExtract}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetExtract.html}", note=[Accessed: 29-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_netextract, organization={Wolfram Research}, title={NetExtract}, year={2020}, url={https://reference.wolfram.com/language/ref/NetExtract.html}, note=[Accessed: 29-March-2025 ]}

@online{reference.wolfram_2025_netextract, organization={Wolfram Research}, title={NetExtract}, year={2020}, url={https://reference.wolfram.com/language/ref/NetExtract.html}, note=[Accessed: 29-March-2025 ]}