"Function" (神经网络解码器)
-
参见
- 函 数
- NetDecoder
- NetEncoder
- NetChain
- NetGraph
-
- 神经网络编码器
- Function
- 相关指南
- 技术笔记
-
-
参见
- 函 数
- NetDecoder
- NetEncoder
- NetChain
- NetGraph
-
- 神经网络编码器
- Function
- 相关指南
- 技术笔记
-
参见
"Function" (神经网络解码器)
NetDecoder[{"Function",f}]
表示一个解码器,把 f 应用到网络的输出并获取解码结果.
更多信息
- NetDecoder[{"Function",…}] 通常用于定义神经网络的自定义后处理.
- NetDecoder[…][input] 把解码器应用到输入产生一个输出.
- NetDecoder[…][{input1,input2,…}] 把解码器应用到输入列表并产生输出列表.
- 在构建网络时,通过指定 "port"->NetDecoder[…] 解码器可以附加在网络的输出端口.
- 支持下列参数:
-
"Properties" {} 可用属性 SaveDefinitions True 是否应自动保存与编码器估算相关的当前定义 Initialization None 首次应用编码器时要估算的表达式 ExcludedContexts Automatic 其符号不会递归保存其定义的上下文 IncludedContexts All 其符号将递归保存其定义的上下文 - NetDecoder[{"Function",f,"Properties"{"prop1","prop2",…}}] 可用于指定解码器支持获取任何 propi. 函数 f 必须接受属性作为第二自变量解码. 在这种情况下,默认的属性提供给 f 的是 prop1,如果没有要求的指定属性.
- 默认情况下,NetDecoder[{"Function",f,…}] 保存估算 f 所需的所有符号的定义,并在解码器的第一次估算时恢复这些定义. 可以使用选项 SaveDefinitions、Initialization、ExcludedContexts 和 IncludedContexts 更改要保存的定义的选择.
参数
范例
打开所有单元 关闭所有单元基本范例 (1)
dec = NetDecoder[{"Function", RGBColor @* Normal}]注意,函数传递一个 NumericArray,并且 Normal 被用于将之转换为 RGBColor 可以接受的标准数组can take.
dec[{0.3, 0.5, 0.2}]net = NetInitialize@NetChain[{3, Tanh}, "Input" -> 2, "Output" -> dec]net[{-100, 6}]参数 (2)
"Properties" (1)
dec = NetDecoder[{"Function", Function[Switch[#2, "x2", #1 * 2, "+1", #1 + 1]], "Properties" -> {"x2", "+1"}}]dec[2]dec[2, "x2"]dec[2, "+1"]net = ElementwiseLayer[Sin, "Output" -> dec]net[2, "x2"]net[2, "+1"]SaveDefinitions (1)
f[x_] := x * 2
g[x_] := f[x] + 1
dec = NetDecoder[{"Function", g}]Clear[f, g]
DownValues /@ {f, g}dec[1]DownValues /@ {f, g}可以使用 SaveDefinitionsFalse 禁用此行为:
dec = NetDecoder[{"Function", g, SaveDefinitions -> False}]dec[1]Clear[f, g]dec[1]DownValues /@ {f, g}可能存在的问题 (1)
许多 Wolfram 语言函数不支持 NumericArray 输入. 该问题可以通过使用 Normal 把 NumericArray 输入转换为标准数组解决:
dec1 = NetDecoder[{"Function", RGBColor}]dec1[{0.3, 0.5, 0.2}]dec2 = NetDecoder[{"Function", RGBColor @* Normal}]dec2[{0.3, 0.5, 0.2}]技术笔记
相关指南
-
▪
- 神经网络