"Function" (Net Decoder)
NetDecoder[{"Function",f}]
represents a decoder that applies f to the output of a net to obtain a decoded result.
Details
- NetDecoder[{"Function",…}] is typically used to define a custom post-processing for a neural network.
- NetDecoder[…][input] applies the decoder to an input to produce an output.
- NetDecoder[…][{input1,input2,…}] 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"->NetDecoder[…] when constructing the net.
- The following parameters are supported:
-
"Properties" {} available properties SaveDefinitions True whether current definitions relevant for the evaluation of the encoder should automatically be saved Initialization None expression to be evaluated when the encoder is first applied ExcludedContexts Automatic contexts whose symbols will not have their definitions recursively saved IncludedContexts All contexts whose symbols will have their definitions recursively saved - NetDecoder[{"Function",f,"Properties"{"prop1","prop2",…}}] can be used to specify that the decoder supports obtaining any of the propi. 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 prop1.
- By default, NetDecoder[{"Function",f,…}] saves the definitions of all the symbols needed to evaluate f, and restores these definitions at the first evaluation of the decoder. The selection of definitions to be saved can be changed using options SaveDefinitions, Initialization, ExcludedContexts and IncludedContexts.
Parameters
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Create a property that interprets its input as an RGB color:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-gfwb36
Note that the function is passed a NumericArray and that Normal is used to convert it to a standard array that RGBColor can take.
Decode a 3-vector as an RGB color:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-q05whz
Attach the decoder to a randomly generated net:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-hil06g
The output of the net is automatically decoded as a color:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-c3crye
Parameters (2)
"Properties" (1)
Define a decoder with two possible properties "x2" and "+1":
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-eh4p85
By default, the decoder returns the first property:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-xydkir
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-4nky4
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-5daf0a
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-82s5kh
Compute several output properties of the net applied to an input:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-xzk9nv
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-yxw37m
SaveDefinitions (1)
By default, definitions needed to evaluate the decoder are saved:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-k6hedq
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-6ozpvw
When applying the encoder for the first time, definitions are restored:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-61wup2
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-tgahql
This behavior can be disabled using SaveDefinitionsFalse:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-y5oyt2
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-j4tcji
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-s0jsjw
Definitions cannot be restored:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-ckn0pv
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-vdwjgf
Possible Issues (1)Common pitfalls and unexpected behavior
Many Wolfram Language functions do not support NumericArray inputs. This issue can be solved by using Normal to convert a NumericArray input to a standard array:
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-7fw1b
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-cwjtjq
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-gqmqi
https://wolfram.com/xid/0b6j8pyk7srpg750m9gx26-h75f6y