({{, (RefLink[NetDecoder, paclet:ref/NetDecoder])[{"Function",f}] 
represents a decoder that applies f to the output of a net to obtain a decoded result.}})

OpenersNotesSection(Spacer1)Details

(RefLink[NetDecoder, paclet:ref/NetDecoder])[…][input] applies the decoder to an input to produce an output.

(RefLink[NetDecoder, paclet:ref/NetDecoder])[…][{(Subscript[input, 1]),(Subscript[input, 2]),…}] applies the decoder to a list of inputs to produce a list of outputs.

A decoder can be attached to an output port of a net by specifying "port"->(RefLink[NetDecoder, paclet:ref/NetDecoder])[…] when constructing the net.

(RefLink[NetDecoder, paclet:ref/NetDecoder])[{"Function",f,"Properties"->{"(Subscript[prop, 1])","(Subscript[prop, 2])",…}}] can be used to specify that the decoder supports obtaining any of the (Subscript[prop, i]). The function f must then take the property to decode as its second argument. In this case, the default property that will be supplied to f if no specific property is requested is (Subscript[prop, 1]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (2)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Create a property that interprets its input as an RGB color:

dec=NetDecoder[{"Function",RGBColor/*Normal}]

Note that the function is passed a (RefLink[NumericArray, paclet:ref/NumericArray]) and that (RefLink[Normal, paclet:ref/Normal]) is used to convert it to a standard array that (RefLink[RGBColor, paclet:ref/RGBColor]) can take.

Decode a 3-vector as an RGB color:

dec[{0.3,0.5,0.2}]

Attach the decoder to a randomly generated net:

net=NetInitialize@NetChain[{3,Tanh},"Input"->2,"Output"->dec]

The output of the net is automatically decoded as a color:

net[{-100,6}]

OpenersExampleSection2(Spacer1)Possible Issues  (1)

Many Wolfram Language functions do not support (RefLink[NumericArray, paclet:ref/NumericArray]) inputs. This issue can be solved by using (RefLink[Normal, paclet:ref/Normal]) to convert a (RefLink[NumericArray, paclet:ref/NumericArray]) input to a standard array:

dec1=NetDecoder[{"Function",RGBColor}]

dec1[{0.3,0.5,0.2}]

dec2=NetDecoder[{"Function",RGBColor}]

dec2[{0.3,0.5,0.2}]