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 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 allBasic Examples (4)
Create a randomly initialized layer:
Extract the weight matrix from the layer:
Create a NetChain:
Create an operator containing a net:
Extract the net from inside the operator:
Create a NetEncoder:
Scope (6)
Create a NetChain with named layers:
Extract the function used in the elementwise layer:
Create an initialized NetChain:
Extract the weights from a specific layer:
Extract the weights from all layers:
Create a NetGraph object with named layers:
Create a layer with specific input dimensions:
Extract the output dimensions:
Create a layer with an attached 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:
Text
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.
APA
Wolfram Language. (2016). NetExtract. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetExtract.html