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.
NetExtract[spec]
represents an operator form of NetExtract that can be applied to an expression.
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.
NetExtract[spec]
represents an operator form of NetExtract that can be applied to an expression.
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 all close allBasic Examples (4)
Create a randomly initialized layer:
layer = NetInitialize @ LinearLayer[2, "Input" -> 2]Extract the weight matrix from the layer:
NetExtract[layer, "Weights"]//NormalCreate a NetChain:
chain = NetChain[{1, 2, 3}]NetExtract[chain, 3]Create an operator containing a net:
op = NetMapOperator[LinearLayer[5]]Extract the net from inside the operator:
NetExtract[op, "Net"]Create a NetEncoder:
encoder = NetEncoder["Image"]NetExtract[encoder, "Type"]Extract the output dimensions of the encoder:
NetExtract[encoder, "Output"]Extract the color space of the encoder:
NetExtract[encoder, "ColorSpace"]Scope (7)
Create a NetChain with named layers:
chain = NetChain[<|"x" -> LinearLayer[5], "y" -> Ramp, "z" -> LinearLayer[10]|>]NetExtract[chain, 1]NetExtract[chain, -1]NetExtract[chain, "y"]Extract the function used in the elementwise layer:
NetExtract[chain, {2, "Function"}]NetExtract[chain, {{1}, {3}}]NetExtract[chain, All]Create an initialized NetChain:
chain = NetInitialize @ NetChain[<|"a" -> 2, "b" -> 2, "c" -> 2|>, "Input" -> 2]Extract the weights from a specific layer:
NetExtract[chain, {2, "Weights"}]Extract the weights from all layers:
NetExtract[chain, {All, "Weights"}]Create a NetGraph object with named layers:
graph = NetGraph[<|"linear1" -> LinearLayer[2], "linear2" -> LinearLayer[5]|>, {"linear1" -> "linear2"}]NetExtract[graph, "linear1"]NetExtract[graph, All]Create a layer with specific input dimensions:
net = FlattenLayer["Input" -> {5, 5}]NetExtract[net, "Input"]Extract the output dimensions:
NetExtract[net, "Output"]Create a layer with an attached encoder:
net = PoolingLayer[5, "Input" -> NetEncoder["Image"]]NetExtract[net, "Input"]Extract a parameter of the input encoder:
NetExtract[net, {"Input", "ImageSize"}]Extract the type and output dimensions of the input encoder:
NetExtract[net, {"Input", {"Type", "Output"}}]Extract the value of all shared arrays in a network:
net = NetInitialize[NetChain[{NetInsertSharedArrays[EmbeddingLayer[3]], NetInsertSharedArrays[LinearLayer[2]]}]]NetExtract[net, NetArray[All]]NetExtract[net, NetArray["Weights"]]In this example, NetArray["Weights"] corresponds to the value of the weights in all layers:
NetExtract[net, {All, "Weights"}]Use a NetExtract operator:
NetExtract[1]@NetChain[{ElementwiseLayer[Sin], SummationLayer[]}]Properties & Relations (1)
The part specifications supported by NetExtract are identical to those used by NetReplacePart. Extract the weights of the third layer of a NetChain:
partSpec = {3, "Weights"};net = NetInitialize@NetChain[{LinearLayer[2], Ramp, LinearLayer[3], Ramp}, "Input" -> {3}];NetExtract[net, partSpec]Use the same specification to replace the weights:
NetReplacePart[net, partSpec -> {{1, 2}, {3, 4}, {5, 6}}]Possible Issues (1)
Create a ConvolutionLayer:
conv = ConvolutionLayer[3, {2, 2}]Attempting to extract the weights of this uninitialized layer returns Automatic:
NetExtract[conv, "Weights"]Known parameters can be extracted:
NetExtract[conv, "KernelSize"]Related Guides
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
BibTeX
@misc{reference.wolfram_2026_netextract, author="Wolfram Research", title="{NetExtract}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetExtract.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_netextract, organization={Wolfram Research}, title={NetExtract}, year={2020}, url={https://reference.wolfram.com/language/ref/NetExtract.html}, note=[Accessed: 12-June-2026]}