({{, (RefLink[NetInsertSharedArrays, paclet:ref/NetInsertSharedArrays])[net] 
converts all ordinary arrays in net into (RefLink[NetSharedArray, paclet:ref/NetSharedArray]) objects.}, {, (RefLink[NetInsertSharedArrays, paclet:ref/NetInsertSharedArrays])[net,"prefix"]
uses a prefix for the names of all newly shared arrays. }})

OpenersNotesSection(Spacer1)Details

Each array in the net will be shared using a name that is derived from its position within the net.

By sharing all arrays in a net, multiple instances of that net within a larger net will behave identically during training and evaluation.

OpenersPrimaryExamplesSection(Spacer1)Examples  (4)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Convert arrays in a layer into shared arrays:

NetInsertSharedArrays[LinearLayer[2,"Input"->2]]

Convert arrays in a layer into shared arrays, using a specific prefix:

NetInsertSharedArrays[LinearLayer[2,"Input"->2],"Linear/"]

Convert arrays in layers within a net into shared arrays:

NetInsertSharedArrays[NetChain[{2,Ramp,3}]]

OpenersExampleSection2(Spacer1)Properties & Relations  (1)

Insert shared arrays into a layer:

layer=NetInsertSharedArrays[LinearLayer[2,"Input"->2]]

When used multiple times in a larger network, only one set of weights will be created and stored:

net=NetInitialize[NetChain[{layer,Ramp,layer}]]

When extracted, the weights for layers 1 and 3 are identical:

NetExtract[net,{{1,"Weights"},{3,"Weights"}}]//Map[Normal]

The underlying shared array can also be extracted using (RefLink[NetExtract, paclet:ref/NetExtract]):

NetExtract[net,NetSharedArray["Weights"]]//Normal

The amount of storage required for arrays in the entire net is the same as the storage required for a single layer:

NetInformation[{net,layer},"ArraysTotalSize"]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[NetSharedArray, paclet:ref/NetSharedArray])  ▪  (RefLink[NetExtract, paclet:ref/NetExtract])  ▪  (RefLink[NetReplacePart, paclet:ref/NetReplacePart])  ▪  (RefLink[NetInitialize, paclet:ref/NetInitialize])  ▪  (RefLink[NetTrain, paclet:ref/NetTrain])  ▪  (RefLink[NetInformation, paclet:ref/NetInformation])}})}})

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

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