MaxPool3d
- classtorch.nn.MaxPool3d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)[源代码]
-
对由多个输入平面组成的输入信号进行三维最大池化操作。
在最简单的情况下,对于输入大小为$(N, C, D, H, W)$、输出为$(N, C, D_{out}, H_{out}, W_{out})$且
kernel_size
为$(kD, kH, kW)$的层,其输出值可以精确描述为:$\begin{aligned} \text{out}(N_i, C_j, d, h, w) ={} & \max_{k=0, \ldots, kD-1} \max_{m=0, \ldots, kH-1} \max_{n=0, \ldots, kW-1} \\ & \text{input}(N_i, C_j, \text{stride[0]} \times d + k, \text{stride[1]} \times h + m, \text{stride[2]} \times w + n) \end{aligned}$如果
padding
不为零,输入数据会在两侧隐式地用负无穷进行填充,每侧填充的点数与padding
指定的数量相同。dilation
控制卷积核中各点之间的间距。虽然难以描述清楚,但这个 链接 提供了一个很好的可视化示例来帮助理解dilation
的作用。注意
当 ceil_mode=True 时,如果滑动窗口始于左填充区域或输入区域,则允许其超出边界。而那些原本应从右填充区域开始的滑动窗口则会被忽略。
参数
kernel_size
、stride
、padding
和dilation
可以是:-
一个单独的
int
— 在这种情况下,这个值将同时应用于深度、高度和宽度这三个维度。 -
一个包含三个整数的
元组
– 在这种情况下,第一个整数表示深度维度,第二个整数表示高度维度,第三个整数表示宽度维度。
- 参数
-
-
kernel_size (Union[int, Tuple[int, int, int]]) – 窗口大小,用于计算最大值
-
stride (Union[int, Tuple[int, int, int]]) – 窗口的步幅。默认值为
kernel_size
-
padding (Union[int, Tuple[int, int, int]]) – 在所有三边添加的隐式负无穷大填充
-
return_indices (bool) – 如果为
True
,将与输出一起返回最大值的索引。这对于后续使用torch.nn.MaxUnpool3d
时非常有用。 -
ceil_mode (bool) – 当设置为 True 时,使用 ceil 而不是 floor 来计算输出形状
-
- 形状:
-
-
输入: $(N, C, D_{in}, H_{in}, W_{in})$ 或 $(C, D_{in}, H_{in}, W_{in})$.
-
输出为:$(N, C, D_{out}, H_{out}, W_{out})$ 或 $(C, D_{out}, H_{out}, W_{out})$,其中
$D_{out} = \left\lfloor\frac{D_{in} + 2 \times \text{padding}[0] - \text{dilation}[0] \times (\text{kernel\_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor$$H_{out} = \left\lfloor\frac{H_{in} + 2 \times \text{padding}[1] - \text{dilation}[1] \times (\text{kernel\_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor$$W_{out} = \left\lfloor\frac{W_{in} + 2 \times \text{padding}[2] - \text{dilation}[2] \times (\text{kernel\_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor$
-
示例:
>>> # pool of square window of size=3, stride=2 >>> m = nn.MaxPool3d(3, stride=2) >>> # pool of non-square window >>> m = nn.MaxPool3d((3, 2, 2), stride=(2, 1, 2)) >>> input = torch.randn(20, 16, 50, 44, 31) >>> output = m(input)
-