NetReplacePart
✖
NetReplacePart
returns a new layer or network in which an input or output port has the specified type.
returns a new NetChain or NetGraph in which the layer identified by lspec has been replaced.
sets a shared array within a network or layer to a specified value.
returns a new NetEncoder[…] or NetDecoder[…] in which a parameter has been replaced.
makes a replacement of a part pspec of a layer or coder lspec within a NetGraph or NetChain.
Details
- NetReplacePart can replace layer parameters, layer arrays, layers, encoders, decoders, encoder parameters, decoder parameters, input array sizes and output array sizes.
- The part specifications supported by NetReplacePart are identical to those used by NetExtract.
- When replacing an array within a layer, the new value must have the same dimensions as the original array.
- When replacing an input or an output in order to fully specify a partially specified network, any of the following values can be used to specify the type of the port:
-
"Real" a single real number "Integer" a single integer n a vector of length n {n1,n2,…} an array of dimensions n1×n2×… "Varying" a variable-length vector {"Varying",n2,n3,…} an array whose first dimension is variable and remaining dimensions are n2×n3×… Automatic an array with a shape that should be inferred NetEncoder[…] an encoder (for input ports) NetDecoder[…] a decoder (for output ports) - An encoder or decoder can be removed from a port by specifying the value None.
- Changing the output dimension of a NetChain or NetGraph is in general possible, but might require changing intermediate layers, using syntax like NetReplacePart[net,{layernamenewlayer,"Output"newoutput}].
- NetReplacePart will fail if the replacement specifications lead to a net with incompatible dimensions.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
https://wolfram.com/xid/0btogradv5n2-4zuxsu
Obtain a new model in which the input NetEncoder has been removed:
https://wolfram.com/xid/0btogradv5n2-ji49et
Obtain a new model that can be trained on a different set of classes:
https://wolfram.com/xid/0btogradv5n2-1im7et
Obtain a new model in which the first activation layer has been replaced:
https://wolfram.com/xid/0btogradv5n2-4fw0r
Obtain a new model in which the first convolution biases have been randomized:
https://wolfram.com/xid/0btogradv5n2-ua6w6p
Scope (10)Survey of the scope of standard use cases
Create an existing model that contains a DropoutLayer with dropout probability 0.5:
https://wolfram.com/xid/0btogradv5n2-1e447d
Update the dropout probability:
https://wolfram.com/xid/0btogradv5n2-gc39m8
Create a linear layer with no weight matrix specified:
https://wolfram.com/xid/0btogradv5n2-ceyfgh
Insert specific weights and biases:
https://wolfram.com/xid/0btogradv5n2-bmwrxh
Evaluate the layer on an input:
https://wolfram.com/xid/0btogradv5n2-imvd5i
Create a layer without an input encoder:
https://wolfram.com/xid/0btogradv5n2-r7clxl
https://wolfram.com/xid/0btogradv5n2-virvky
Attach a "Class" encoder to the input of the layer, which embeds the classes as {1,0} and {0,1}:
https://wolfram.com/xid/0btogradv5n2-o1n3uh
The resulting layer can now take the values True and False as inputs:
https://wolfram.com/xid/0btogradv5n2-9c3ukw
https://wolfram.com/xid/0btogradv5n2-vhxz24
Add type information to an existing net:
https://wolfram.com/xid/0btogradv5n2-jc3tnh
https://wolfram.com/xid/0btogradv5n2-88wvjd
https://wolfram.com/xid/0btogradv5n2-koj3c6
https://wolfram.com/xid/0btogradv5n2-2fb71f
https://wolfram.com/xid/0btogradv5n2-txu9g3
https://wolfram.com/xid/0btogradv5n2-7up1mx
https://wolfram.com/xid/0btogradv5n2-4uwegm
https://wolfram.com/xid/0btogradv5n2-zzettt
https://wolfram.com/xid/0btogradv5n2-itvhfc
Reshape an existing layer to have different input and output dimensions. Create a layer with a specific NetEncoder:
https://wolfram.com/xid/0btogradv5n2-n53epp
https://wolfram.com/xid/0btogradv5n2-jgwqdg
Replace the input NetEncoder and output NetDecoder:
https://wolfram.com/xid/0btogradv5n2-bu5t8n
Apply the resized layer to an input:
https://wolfram.com/xid/0btogradv5n2-u3v715
Replace the second layer within a NetChain:
https://wolfram.com/xid/0btogradv5n2-4uykgb
https://wolfram.com/xid/0btogradv5n2-0iidfg
Replace a property of an existing NetEncoder:
https://wolfram.com/xid/0btogradv5n2-lm2wrx
https://wolfram.com/xid/0btogradv5n2-tumieq
Replace the value of a shared array in a network:
https://wolfram.com/xid/0btogradv5n2-7b1086
https://wolfram.com/xid/0btogradv5n2-oygmvl
The weights have been replaced by the new value and are still shared:
https://wolfram.com/xid/0btogradv5n2-9g3gxz
https://wolfram.com/xid/0btogradv5n2-scgmvy
Turn a network that processes fixed-length sequences into an equivalent network that handles variable-length sequences:
https://wolfram.com/xid/0btogradv5n2-wsfelk
https://wolfram.com/xid/0btogradv5n2-vstokx
Turn a network that processes strings in a fixed-length fashion into an equivalent network that handles variable-length strings without padding nor clipping:
https://wolfram.com/xid/0btogradv5n2-hw612s
https://wolfram.com/xid/0btogradv5n2-pulihc
https://wolfram.com/xid/0btogradv5n2-c0mkiw
https://wolfram.com/xid/0btogradv5n2-jnd4p8
Properties & Relations (1)Properties of the function, and connections to other functions
The part specifications supported by NetReplacePart are identical to those used by NetExtract.
Wolfram Research (2016), NetReplacePart, Wolfram Language function, https://reference.wolfram.com/language/ref/NetReplacePart.html (updated 2020).
Text
Wolfram Research (2016), NetReplacePart, Wolfram Language function, https://reference.wolfram.com/language/ref/NetReplacePart.html (updated 2020).
Wolfram Research (2016), NetReplacePart, Wolfram Language function, https://reference.wolfram.com/language/ref/NetReplacePart.html (updated 2020).
CMS
Wolfram Language. 2016. "NetReplacePart." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetReplacePart.html.
Wolfram Language. 2016. "NetReplacePart." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetReplacePart.html.
APA
Wolfram Language. (2016). NetReplacePart. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetReplacePart.html
Wolfram Language. (2016). NetReplacePart. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetReplacePart.html
BibTeX
@misc{reference.wolfram_2024_netreplacepart, author="Wolfram Research", title="{NetReplacePart}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetReplacePart.html}", note=[Accessed: 08-January-2025
]}
BibLaTeX
@online{reference.wolfram_2024_netreplacepart, organization={Wolfram Research}, title={NetReplacePart}, year={2020}, url={https://reference.wolfram.com/language/ref/NetReplacePart.html}, note=[Accessed: 08-January-2025
]}