NetArray
NetArray[]
represents an array in a net.
NetArray["name"]
uses "name" as an identifier to share the array in more than one layer.
NetArray[propvalue]
specifies the property prop for the array.
NetArray["Name"name,"Array"array,…]
specifies several properties for the array.
Details
- NetArray is typically used to share arrays in NetChain/NetGraph or to define learnable parameters in FunctionLayer[…].
- All net arrays sharing the same name in a net are treated as the same underlying array by NetInitialize, NetTrain, etc.
- The properties that can be specified are:
-
"Array" initial values or inialization method for the array "Dimensions" dimensions of the array "Name" name of the array, so that it can be shared - NetArray[] automatically gives a name (UUID) to the array and is equivalent to NetArray[Automatic].
- NetInsertSharedArrays[layer] will return a new layer in which all its arrays have been replaced with named net arrays.
Examples
Basic Examples (3)
Create a layer containing a shared array:
Create a chain that contains a shared array, used in two layers:
The weights from the two linear layers are the same (and will remain the same when training with NetTrain):
Extract all the shared arrays of a net:
Define a FunctionLayer that adds a list of learnable values to a list, initialized with arbitrary values:
Evaluate the layer on an input list:
The original NetArray corresponds to a NetArrayLayer in the equivalent NetGraph:
Text
Wolfram Research (2020), NetArray, Wolfram Language function, https://reference.wolfram.com/language/ref/NetArray.html.
CMS
Wolfram Language. 2020. "NetArray." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NetArray.html.
APA
Wolfram Language. (2020). NetArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetArray.html