NetExtract

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)

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, NetArray["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:

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

BibTeX

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

BibLaTeX

@online{reference.wolfram_2021_netextract, organization={Wolfram Research}, title={NetExtract}, year={2020}, url={https://reference.wolfram.com/language/ref/NetExtract.html}, note=[Accessed: 20-October-2021 ]}

CMS

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