評價此頁

MaxUnpool1d#

class torch.nn.modules.pooling.MaxUnpool1d(kernel_size, stride=None, padding=0)[原始碼]#

計算 MaxPool1d 的部分逆運算。

MaxPool1d 不是完全可逆的,因為非最大值會被丟失。

要計算 MaxPool1d 的逆運算,需要提供 MaxPool1d 的輸出(包括最大值的索引),並計算一個部分逆運算,其中所有非最大值都設定為零。

注意

當輸入索引存在重複值時,此操作可能表現出非確定性。更多資訊請參閱 pytorch/pytorch#80827可復現性

注意

MaxPool1d 可以將多種輸入大小對映到相同的輸出大小。因此,逆運算可能會出現歧義。為了解決這個問題,您可以在前向傳播呼叫中提供所需的輸出大小作為附加引數 output_size。請參閱下面的輸入和示例。

引數
  • kernel_size (inttuple) – 最大池化視窗的大小。

  • stride (inttuple) – 最大池化視窗的步幅。預設為 kernel_size

  • padding (inttuple) – 新增到輸入的填充。

輸入
  • input: the input Tensor to invert

  • indices: 由 MaxPool1d 給出的索引

  • output_size (optional): the targeted output size

形狀
  • 輸入: (N,C,Hin)(N, C, H_{in})(C,Hin)(C, H_{in})

  • 輸出: (N,C,Hout)(N, C, H_{out})(C,Hout)(C, H_{out}),其中

    Hout=(Hin1)×stride[0]2×padding[0]+kernel_size[0]H_{out} = (H_{in} - 1) \times \text{stride}[0] - 2 \times \text{padding}[0] + \text{kernel\_size}[0]

    or as given by output_size in the call operator

示例

>>> pool = nn.MaxPool1d(2, stride=2, return_indices=True)
>>> unpool = nn.MaxUnpool1d(2, stride=2)
>>> input = torch.tensor([[[1., 2, 3, 4, 5, 6, 7, 8]]])
>>> output, indices = pool(input)
>>> unpool(output, indices)
tensor([[[ 0.,  2.,  0.,  4.,  0.,  6.,  0., 8.]]])

>>> # Example showcasing the use of output_size
>>> input = torch.tensor([[[1., 2, 3, 4, 5, 6, 7, 8, 9]]])
>>> output, indices = pool(input)
>>> unpool(output, indices, output_size=input.size())
tensor([[[ 0.,  2.,  0.,  4.,  0.,  6.,  0., 8.,  0.]]])

>>> unpool(output, indices)
tensor([[[ 0.,  2.,  0.,  4.,  0.,  6.,  0., 8.]]])
forward(input, indices, output_size=None)[原始碼]#

執行前向傳播。

返回型別

張量