Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

NetGraph

NetGraph[{layer1,layer2,},{m1n1,m2n2,}]
specifies a neural net defined by a graph in which the output of layer mi is given as input to layer ni.

NetGraph["name1"layer1,"name2"layer2,,{"namem1""namen1",}]
specifies a net with explicitly named layers.

DetailsDetails

  • For a net with a single input port, NetGraph[][data] gives the result of applying the net to data.
  • For a net with multiple input ports, NetGraph[][<|port1->data1,|>] provides data to each port.
  • For a net with a single output port, NetGraph[][data] gives the output for that port.
  • For a net with multiple output ports, NetGraph[][data,portn] gives the output for the port named portn. NetGraph[][data] or NetGraph[][data,All] gives an association of the outputs for all ports.
  • If one or more input or output ports of any layers are left unconnected, these will become ports of the entire NetGraph.
  • If the n^(th) layer has more than one input port or more than one output port, these can be disambiguated by writing NetPort[n,"port"].
  • Input or output ports for the entire NetGraph can be created by specifying NetPort["input"]-> or ->NetPort["output"] in the list of connections.
  • If multiple output ports of layers are left unconnected and share the same name, they will be become separate ports of the entire NetGraph with names "Port1", "Port2", etc.
  • If a layer has a port that accepts multiple inputs, such as CatenateLayer or SummationLayer, those can be specified by {m1,m2,}->n.
  • A linear chain of connections within the graph can be specified as layer1->layer2->->layern, which will cause each layeri to be connected to layeri+1.
  • When ambiguous, the tensor shapes of input and output ports of the entire graph can be specified with options of the form "port"shape. Valid shapes include:
  • na vector of length n
    {n1,n2,}a tensor of dimensions n1×n2×
    NetEncoder[]an encoder (for input ports)
    NetDecoder[]a decoder (for output ports)
    "type"NetEncoder["type"] or NetDecoder["type"]
  • NetGraph supports the following special layer specifications:
  • nDotPlusLayer[n]
    Ramp,LogisticSigmoid,ElementwiseLayer[f]
  • The StandardForm of NetGraph shows the connectivity of layers in the graph, and annotates edges with the size of the tensor that the edge represents. Clicking a layer in the graph shows more information about that layer.
  • Take[NetGraph[],{start,end}] returns a subgraph of the given NetGraph that contains only the layers that connect start and end. The following forms can be given for start and end:
  • n,"layer"a specified layer
    NetPort[layer,"port"]the specified input or output port of a layer
    NetPort["port"]an input or output port of the entire graph
    Allall of the inputs or outputs of the graph
    {spec1,spec2,}the union of the speci
  • VertexDelete[NetGraph[],layer] deletes one or more layers from a NetGraph, returning a new graph. Layers such as ElementwiseLayer[] that have the same input and output size will be removed such that their output is connected directly to their input.

ExamplesExamplesopen allclose all

Basic Examples  (2)Basic Examples  (2)

Create a net with one layer:

In[1]:=
Click for copyable input
Out[1]=

Apply the net to an input:

In[2]:=
Click for copyable input
Out[2]=

Create a net with two layers:

In[1]:=
Click for copyable input
Out[1]=

Initialize all arrays in the net:

In[2]:=
Click for copyable input

Apply the net to an input:

In[3]:=
Click for copyable input
Out[3]=
Introduced in 2016
(11.0)