捷徑

torch.dsplit

torch.dsplit(input, indices_or_sections) List of Tensors

根據 indices_or_sections,將至少三個維度的張量 input 沿深度方向分割成多個張量。每個分割都是 input 的一個視圖 (view)。

這等同於呼叫 torch.tensor_split(input, indices_or_sections, dim=2) (分割維度為 2),但如果 indices_or_sections 是一個整數,則它必須能整除分割維度,否則會拋出執行階段錯誤。

此函數基於 NumPy 的 numpy.dsplit()

參數
範例:
>>> t = torch.arange(16.0).reshape(2, 2, 4)
>>> t
tensor([[[ 0.,  1.,  2.,  3.],
         [ 4.,  5.,  6.,  7.]],
        [[ 8.,  9., 10., 11.],
         [12., 13., 14., 15.]]])
>>> torch.dsplit(t, 2)
(tensor([[[ 0.,  1.],
        [ 4.,  5.]],
       [[ 8.,  9.],
        [12., 13.]]]),
 tensor([[[ 2.,  3.],
          [ 6.,  7.]],
         [[10., 11.],
          [14., 15.]]]))
>>> torch.dsplit(t, [3, 6])
(tensor([[[ 0.,  1.,  2.],
          [ 4.,  5.,  6.]],
         [[ 8.,  9., 10.],
          [12., 13., 14.]]]),
 tensor([[[ 3.],
          [ 7.]],
         [[11.],
          [15.]]]),
 tensor([], size=(2, 2, 0)))

文件

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources