NetAppend
Details and Options
- The input of the appended layer must be compatible with the output of the final layer in the chain.
- Any NetDecoder previously attached to the end of net will be removed.
- NetAppend takes the following options:
-
"Input" Automatic type for the input of the resulting chain "Output" Automatic type for the output of the resulting chain - Options "Input" and "Output" support the normal type specifications allowed by NetChain, including NetEncoder and NetDecoder.
Examples
open all close allBasic Examples (3)
Append a layer to the end of a chain:
NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[]]Append a named layer to the end of a chain:
NetAppend[NetChain[<|"A" -> 1, "B" -> Tanh, "C" -> 3|>], "D" -> SoftmaxLayer[]]Append several layers to the end of a chain:
NetAppend[NetChain[{1, Tanh, 3}], {Tanh, 5, SoftmaxLayer[]}]Scope (3)
Append a layer and attach a NetDecoder:
NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[], "Output" -> NetDecoder["Class"]]Create a NetChain with NetAppend:
NetAppend[LinearLayer[], Ramp]Append a layer to a NetGraph with one output:
ng = NetGraph[{1, 2, Plus}, {{NetPort["Foo"] -> 1, NetPort["Bar"] -> 2} -> 3}]NetAppend[ng, SummationLayer[]]NetAppend[ng, "Sum" -> SummationLayer[]]Options (6)
"Input" (3)
Set the input shape of the net:
NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[], "Input" -> {3}]Set a NetEncoder for the net:
NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[], "Input" -> NetEncoder[{"Class", {x, y, z}}]]Using this option is equivalent to using NetReplacePart on the returned net:
net = NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[]]NetReplacePart[net, "Input" -> NetEncoder[{"Class", {x, y, z}}]]"Output" (3)
Set a NetDecoder for the net:
NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[], "Output" -> NetDecoder[{"Class", {x, y, z}}]]Using this option is equivalent to using NetReplacePart on the returned net:
net = NetAppend[NetChain[{1, Tanh, 3}], SoftmaxLayer[]]NetReplacePart[net, "Output" -> NetDecoder[{"Class", {x, y, z}}]]An existing NetDecoder can be added back to the returned net using this option, provided it is compatible with the new final layer:
dec = NetDecoder[{"Class", {x, y, z}}]net = NetChain[{1, Tanh, 3}, "Output" -> dec]NetAppend[net, SoftmaxLayer[]]NetAppend[net, SoftmaxLayer[], "Output" -> dec]Possible Issues (3)
The input of the appended layer must be compatible with the output of the final layer in the chain:
NetAppend[NetChain[{1, 2, 3}], PoolingLayer[{3}]]A layer with several input ports cannot be appended:
NetAppend[NetChain[{1, 2, 3}], AttentionLayer[]]A layer cannot be appended to a network with more than one output:
ng = NetGraph[{1, 2}, {}]NetAppend[ng, LinearLayer[]]Tech Notes
Related Guides
Text
Wolfram Research (2018), NetAppend, Wolfram Language function, https://reference.wolfram.com/language/ref/NetAppend.html (updated 2021).
CMS
Wolfram Language. 2018. "NetAppend." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/NetAppend.html.
APA
Wolfram Language. (2018). NetAppend. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetAppend.html
BibTeX
@misc{reference.wolfram_2026_netappend, author="Wolfram Research", title="{NetAppend}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/NetAppend.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_netappend, organization={Wolfram Research}, title={NetAppend}, year={2021}, url={https://reference.wolfram.com/language/ref/NetAppend.html}, note=[Accessed: 13-June-2026]}