({{, (RefLink[NetInsert, paclet:ref/NetInsert])[chain,layer,i] 
inserts a layer into a (RefLink[NetChain, paclet:ref/NetChain]) before the layer at position i.}, {, (RefLink[NetInsert, paclet:ref/NetInsert])[chain,"name"->layer,"pos"]
inserts a named layer into a (RefLink[NetChain, paclet:ref/NetChain]) before the layer at the given position.}})

OpenersNotesSection(Spacer1)Details

If a chain was created using the association form <|"(Subscript[name, 1])"->(Subscript[layer, 1]),"(Subscript[name, 2])"->(Subscript[layer, 2]),…|>, then (RefLink[NetInsert, paclet:ref/NetInsert])[chain,"name"->layer,pos] should be used.

If a chain was created using the list form {(Subscript[layer, 1]),(Subscript[layer, 2]),…}, then (RefLink[NetInsert, paclet:ref/NetInsert])[chain,layer,i] should be used.

The inserted layer must be compatible with the output of the previous layer and the input of the next layer.

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Insert a layer at the end of a chain:

NetInsert[NetChain[{1,2,3}],Ramp,4]

Insert a named layer in the middle of a chain:

NetInsert[NetChain[<|"A"->1,"B"->2|>],"X"->ElementwiseLayer[Ramp],"B"]

OpenersExampleSection2(Spacer1)Possible Issues  (1)

When inserting a layer into a chain containing named layers, the key must not already exist:

NetInsert[NetChain[<|"A"->1,"B"->2|>],"A"->ElementwiseLayer[Ramp],"B"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NetDelete, paclet:ref/NetDelete])  ▪  (RefLink[NetTake, paclet:ref/NetTake])  ▪  (RefLink[NetDrop, paclet:ref/NetDrop])  ▪  (RefLink[NetExtract, paclet:ref/NetExtract])  ▪  (RefLink[NetFlatten, paclet:ref/NetFlatten])  ▪  (RefLink[NetReplace, paclet:ref/NetReplace])  ▪  (RefLink[NetReplacePart, paclet:ref/NetReplacePart])  ▪  (RefLink[NetRename, paclet:ref/NetRename])  ▪  (RefLink[NetAppend, paclet:ref/NetAppend])  ▪  (RefLink[NetPrepend, paclet:ref/NetPrepend])  ▪  (RefLink[NetChain, paclet:ref/NetChain])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Neural Networks in the Wolfram Language, paclet:tutorial/NeuralNetworksOverview])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Neural Networks, paclet:guide/NeuralNetworks])}})}})