ReshapeLayer
ReshapeLayer[dims]
表示一个网络层,将输入重新诠释为维数为 dims 的数组.
更多信息和选项
- ReshapeLayer 开放下列端口以便用在 NetGraph 等中:
-
"Input" 任意秩的数组 "ReferenceShape" 从数组中复制形状(可选) "Output" 重塑后的数组 - 在 ReshapeLayer[spec] 中,允许使用以下 spec:
-
{dim1,…} 明确指定尺寸 "ReferenceShape" 为 "Reference" 端口提供的数组维度 - 在 ReshapeLayer[dims] 中,列表 dims 中允许有以下元素:
-
n 显式指定大小 Inherited 复制输入的大小 Automatic 根据其他维度的大小推断大小 All 从输入复制余下维度的大小 - 维度列表中只能出现一个 Automatic 或一个 All.
- 输入数组中元素的总数等于输出数组中元素的总数.
- ReshapeLayer 通常会根据其在 NetChain 等中的上下文推断其输入的维度. 要将维度明确指定为 {n1,n2,…},使用 ReshapeLayer["Input"->{n1,n2,…}].
- ReshapeLayer[…][input] 明确计算将该网络层应用于 input 的输出.
- ReshapeLayer[…][{input1,input2,…}] 明确计算每个 inputi 的输出.
- 使用 "ReferenceShape" 重塑规格,输入可以是 ReshapeLayer[…][<"Input"input,"ReferenceShape"ref >] 或 ReshapeLayer[…][<"Input"{input1,…},"ReferenceShape"{ref1,…} >].
- 当输入 NumericArray 时,输出将是 NumericArray.
- Options[ReshapeLayer] 给出了构建网络层的默认选项列表. Options[ReshapeLayer[…]] 给出了默认选项列表,以便根据某些数据对网络层进行运算.
- Information[ReshapeLayer[…]] 给出该网络层的报告.
- Information[ReshapeLayer[…],prop] 给出 ReshapeLayer[…] 属性 prop 的值. 可能的属性和 NetGraph 的相同.
范例
打开所有单元关闭所有单元基本范例 (3)
创建 ReshapeLayer 将任意输入的形状改变为 2x3 矩阵:
创建 ReshapeLayer 将任意输入的形状变成 2x3 矩阵:
创建一个 ReshapeLayer 重塑长度为 1 的向量为单个数字:
范围 (5)
创建一个 ReshapeLayer,调整对特定大小的输入数组进行调整:
创建一个 ReshapeLayer,把一个数字调整为 1×1 的矩阵:
创建一个 ReshapeLayer 复制输入的第一个维度大小并根据其他推断第四维度的大小:
创建一个 ReshapeLayer,在数组的最深层添加大小为 1 的维数:
创建一个 ReshapeLayer,重塑输入,使其与参考数组的形状相匹配:
应用 (1)
创建一个 ReshapeLayer,获取 32×32 RGB 图像并返回 96×32 灰度图像:
属性和关系 (3)
可以用 ReshapeLayer 来实现 FlattenLayer. 通过将2×3×3 数组调整成正确的输出维度,把它的前两个维度压平:
当输入大小由 NetReplacePart 改变,规范 Automatic 和 Inherited 允许 ReshapeLayer 重新计算输出大小. 创建一个 ReshapeLayer:
如果用固定的规范创建同样的 ReshapeLayer,调整大小会导致失败:
对于整数维度规范,ReshapeLayer 计算:
可能存在的问题 (2)
巧妙范例 (2)
文本
Wolfram Research (2016),ReshapeLayer,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ReshapeLayer.html (更新于 2020 年).
CMS
Wolfram 语言. 2016. "ReshapeLayer." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2020. https://reference.wolfram.com/language/ref/ReshapeLayer.html.
APA
Wolfram 语言. (2016). ReshapeLayer. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ReshapeLayer.html 年