NetReplace

NetReplace[net,pattlayer]

gives a net in which all layers matching patt are replaced with layer.

NetReplace[net,{rule1,rule2,}]

performs all replacements specified by the rulei.

Details and Options

  • The patterns can be either expressions that match a specific net head, such as _ElementwiseLayer, or literal layers, such as ElementwiseLayer[Ramp].
  • When a literal layer is matched, all user-provided parameters must match exactly. Input and output dimensions need not match.
  • Layers will be matched at any depth in the original net.
  • If the replacement value is Nothing, the corresponding layer of the net will be dropped.
  • If no replacements are performed, a message will be issued and the original net will be returned.

Examples

open allclose all

Basic Examples  (3)

Replace all layers of a specified type with a different layer:

Replace all layers matching a specified type and parameter settings with a new layer:

Remove all layers of a specified type:

Properties & Relations  (1)

Replacing a layer with a NetChain will collapse the chain into any parent chain:

Possible Issues  (1)

If no pattern matches occur, a message will be given:

Wolfram Research (2018), NetReplace, Wolfram Language function, https://reference.wolfram.com/language/ref/NetReplace.html.

Text

Wolfram Research (2018), NetReplace, Wolfram Language function, https://reference.wolfram.com/language/ref/NetReplace.html.

CMS

Wolfram Language. 2018. "NetReplace." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NetReplace.html.

APA

Wolfram Language. (2018). NetReplace. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetReplace.html

BibTeX

@misc{reference.wolfram_2024_netreplace, author="Wolfram Research", title="{NetReplace}", year="2018", howpublished="\url{https://reference.wolfram.com/language/ref/NetReplace.html}", note=[Accessed: 23-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_netreplace, organization={Wolfram Research}, title={NetReplace}, year={2018}, url={https://reference.wolfram.com/language/ref/NetReplace.html}, note=[Accessed: 23-November-2024 ]}