NetRename[net,"old""new"]
gives a net in which the name old for a layer is replaced with new.
NetRename[net,NetPort["old"]NetPort["new"]]
gives a net in which the name old for an input or output port is replaced with new.
NetRename[net,{rule1,rule2,…}]
performs all renamings specified by the rulei.
NetRename[net,f]
uses a function f to map existing layer names to new names.
NetRename[net,rules,levelspec]
renames layers and ports nested at level levelspec.
NetRename
NetRename[net,"old""new"]
gives a net in which the name old for a layer is replaced with new.
NetRename[net,NetPort["old"]NetPort["new"]]
gives a net in which the name old for an input or output port is replaced with new.
NetRename[net,{rule1,rule2,…}]
performs all renamings specified by the rulei.
NetRename[net,f]
uses a function f to map existing layer names to new names.
NetRename[net,rules,levelspec]
renames layers and ports nested at level levelspec.
Details
- NetRename is typically used to rename layers and ports in NetChain and NetGraph objects.
- In NetRename[net,rules,levelspec], levelspec can be:
-
n levels 1 through n {n} level n only {n1,n2} levels n1 through n2 - By default, NetRename will only perform renaming at the outermost level of a NetChain or NetGraph. It will not affect nested chains and graphs.
Examples
open all close allBasic Examples (1)
Rename a single layer in a NetChain:
chain = NetChain[<|"a" -> LinearLayer[1], "b" -> ElementwiseLayer[Ramp]|>]NetRename[chain, "a" -> "A"]Scope (4)
Rename a single layer in a NetGraph:
graph = NetGraph[<|"a" -> LinearLayer[1], "b" -> ElementwiseLayer[Ramp]|>, {"a" -> "b"}]NetRename[graph, "a" -> "A"]Rename multiple layers simultaneously:
graph = NetGraph[<|"a" -> LinearLayer[1], "b" -> ElementwiseLayer[Ramp]|>, {"a" -> "b"}]NetRename[graph, {"a" -> "A", "b" -> "B"}]Rename layers using a renaming function:
graph = NetGraph[<|"a" -> LinearLayer[1], "b" -> ElementwiseLayer[Ramp]|>, {"a" -> "b"}]NetRename[graph, ToUpperCase]Rename layers up to level 2 in NetChain and NetGraph containers:
net = NetExtract[
NetModel["OpenCLIP Multi-domain Feature Extractor Trained on DataComp-1B Data", "UninitializedEvaluationNet"],
"transformer"
]renamedNet = NetRename[net, ToUpperCase, 2]Layer names at level 2 have been converted to uppercase:
NetExtract[renamedNet, 3]Layer names at level 3 are unchanged:
NetExtract[renamedNet, {3, "SELF-ATTENTION"}]Tech Notes
Related Guides
Text
Wolfram Research (2018), NetRename, Wolfram Language function, https://reference.wolfram.com/language/ref/NetRename.html (updated 2021).
CMS
Wolfram Language. 2018. "NetRename." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/NetRename.html.
APA
Wolfram Language. (2018). NetRename. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetRename.html
BibTeX
@misc{reference.wolfram_2026_netrename, author="Wolfram Research", title="{NetRename}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/NetRename.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_netrename, organization={Wolfram Research}, title={NetRename}, year={2021}, url={https://reference.wolfram.com/language/ref/NetRename.html}, note=[Accessed: 13-June-2026]}