NetPort

NetPort["port"]

represents the specified input or output port for a complete net.

NetPort[{n,"port"}]

represents the specified port for layer number n in a NetGraph or similar construct.

NetPort[{"name","port"}]

represents the specified port for the layer with the specified name.

NetPort[spec,port]

is treated as equivalent to NetPort[{spec,port}].

NetPort[{spec1,spec2,,"port"}]

permits access to the port of nested layers in a NetGraph or a NetChain.

NetPort[All,"States"]

represents the set of all states in a net associated with recurrent layers such as LongShortTermMemoryLayer.

Details

  • When used in NetGraph, NetPort[{layer,"port"}] refers to the named output port of a layer when used on the left-hand side of a rule, and a named input port of a layer when used on the right-hand side of a rule.
  • When used in a NetGraph, NetPort["port"] refers to an input of the entire graph when used on the left-hand side of a rule, and an output of the entire graph when used on the right-hand side of a rule.
  • net[data,NetPort[oport]] can be used to obtain the value of the net at oport when it is applied to the specified data. oport must refer to an output port, a subnet of the net, or a layer.
  • net[data,{NetPort[oport1],NetPort[oport2],}] returns an association <|NetPort[oport1]->,NetPort[oport2]->,|> whose values are the values of the net at oporti when the net is applied to the specified data.
  • net[data,NetPort[All,"States"]] will return an association of the final recurrent states taken by recurrent layers in a net.
  • net[<|,NetPort[All,"States"]->assoc|>] will set the initial recurrent states used by recurrent layers in a net.

Examples

open allclose all

Basic Examples  (3)

Create a graph with two outputs having custom names:

Create a graph with two inputs having custom names:

Create a graph with a loss layer:

Scope  (3)

Create a NetChain:

Obtain the output of the first layer of the net when applied to data:

This is equivalent to:

This is also equivalent to specifying the layer instead:

Obtain the output of the first two layers of the net:

Obtain the outputs of all layers in the net:

Create a chain that contains a recurrent layer:

The recurrent layer contains two recurrent states:

Evaluate the net on an input:

Obtain an association of the final states of the recurrent layer:

Obtain both the output and the final states:

Set the initial value of the recurrent states:

Create a NetGraph with a nested NetChain:

Compute the output of the second layer of the nested NetChain:

Add this output as a second output of the net:

Connect the second layer of the nested NetChain to another network:

Properties & Relations  (1)

Information can be used to obtain the names of inputs, outputs and recurrent states suitable for use with NetPort:

Possible Issues  (1)

The value of an input port during the evaluation of a net cannot be obtained using NetPort:

Wolfram Research (2016), NetPort, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPort.html (updated 2021).

Text

Wolfram Research (2016), NetPort, Wolfram Language function, https://reference.wolfram.com/language/ref/NetPort.html (updated 2021).

CMS

Wolfram Language. 2016. "NetPort." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/NetPort.html.

APA

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

BibTeX

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

BibLaTeX

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