捷徑

Conv3dNet

class torchrl.modules.Conv3dNet(in_features: ~typing.Optional[int] = None, depth: ~typing.Optional[int] = None, num_cells: ~typing.Optional[~typing.Union[~typing.Sequence[int], int]] = None, kernel_sizes: ~typing.Union[~typing.Sequence[int], int] = 3, strides: ~typing.Union[~typing.Sequence[int], int] = 1, paddings: ~typing.Union[~typing.Sequence[int], int] = 0, activation_class: ~typing.Union[~typing.Type[~torch.nn.modules.module.Module], ~typing.Callable] = <class 'torch.nn.modules.activation.ELU'>, activation_kwargs: ~typing.Optional[~typing.Union[dict, ~typing.List[dict]]] = None, norm_class: ~typing.Optional[~typing.Union[~typing.Type[~torch.nn.modules.module.Module], ~typing.Callable]] = None, norm_kwargs: ~typing.Optional[~typing.Union[dict, ~typing.List[dict]]] = None, bias_last_layer: bool = True, aggregator_class: ~typing.Optional[~typing.Union[~typing.Type[~torch.nn.modules.module.Module], ~typing.Callable]] = <class 'torchrl.modules.models.utils.SquashDims'>, aggregator_kwargs: ~typing.Optional[dict] = None, squeeze_output: bool = False, device: ~typing.Optional[~typing.Union[~torch.device, str, int]] = None)[source]

一個 3D 卷積神經網路。

參數:
  • in_features (int, optional) – 輸入特徵的數量。如果未提供,將使用自動檢索輸入大小的惰性實作。

  • depth (int, optional) – 網路的深度。深度為 1 將產生具有所需輸入大小且輸出大小等於 num_cells 引數最後一個元素的單個線性層網路。如果沒有指示 depth,則 depth 資訊應包含在 num_cells 引數中(請參閱下文)。如果 num_cells 是可迭代的且指示了 depth,則兩者應匹配:len(num_cells) 必須等於 depth

  • num_cells (intint 序列, 選填) – 輸入和輸出之間每一層的 cell 數量。如果提供一個整數,則每一層將具有相同數量的 cell,並且深度將從 depth 取得。如果提供一個可迭代物件,線性層 out_features 將與 num_cells 的內容匹配。預設值為 [32, 32, 32][32] * depth` is depth is not ``None

  • kernel_sizes (int, int 序列, 選填) – conv 網路的 kernel 大小。如果為可迭代物件,則長度必須與深度相符,深度由 num_cells 或 depth 參數定義。預設值為 3

  • strides (intint 序列) – conv 網路的 stride。如果為可迭代物件,則長度必須與深度相符,深度由 num_cells 或 depth 參數定義。預設值為 1

  • activation_class (Type[nn.Module] 或 callable) – 要使用的 activation 類別或建構子。預設值為 Tanh

  • activation_kwargs (dictdicts 列表, 選填) – 與 activation 類別一起使用的 kwargs。也可以提供長度為 depth 的 kwargs 列表,每一層有一個元素。

  • norm_class (Typecallable, 選填) – 正規化類別,如果有的話。

  • norm_kwargs (dictdicts 列表, 選填) – 與正規化層一起使用的 kwargs。也可以提供長度為 depth 的 kwargs 列表,每一層有一個元素。

  • bias_last_layer (bool) – 如果 True,則最後的 Linear 層將具有偏差參數。預設值為 True

  • aggregator_class (Type[nn.Module] 或 callable) – 要在鏈末端使用的 aggregator 類別或建構子。預設值為 SquashDims

  • aggregator_kwargs (dict, 選填) – aggregator_class 建構子的 kwargs。

  • squeeze_output (bool) – 是否應擠壓輸出的單例維度。預設值為 False

  • device (torch.device, 選填) – 在其上建立模組的裝置。

範例

>>> # All of the following examples provide valid, working MLPs
>>> cnet = Conv3dNet(in_features=3, depth=1, num_cells=[32,])
>>> print(cnet)
Conv3dNet(
    (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (1): ELU(alpha=1.0)
    (2): SquashDims()
)
>>> cnet = Conv3dNet(in_features=3, depth=4, num_cells=32)
>>> print(cnet)
Conv3dNet(
    (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (1): ELU(alpha=1.0)
    (2): Conv3d(32, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (3): ELU(alpha=1.0)
    (4): Conv3d(32, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (5): ELU(alpha=1.0)
    (6): Conv3d(32, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (7): ELU(alpha=1.0)
    (8): SquashDims()
)
>>> cnet = Conv3dNet(in_features=3, num_cells=[32, 33, 34, 35])  # defines the depth by the num_cells arg
>>> print(cnet)
Conv3dNet(
    (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (1): ELU(alpha=1.0)
    (2): Conv3d(32, 33, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (3): ELU(alpha=1.0)
    (4): Conv3d(33, 34, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (5): ELU(alpha=1.0)
    (6): Conv3d(34, 35, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (7): ELU(alpha=1.0)
    (8): SquashDims()
)
>>> cnet = Conv3dNet(in_features=3, num_cells=[32, 33, 34, 35], kernel_sizes=[3, 4, 5, (2, 3, 4)])  # defines kernels, possibly rectangular
>>> print(cnet)
Conv3dNet(
    (0): Conv3d(3, 32, kernel_size=(3, 3, 3), stride=(1, 1, 1))
    (1): ELU(alpha=1.0)
    (2): Conv3d(32, 33, kernel_size=(4, 4, 4), stride=(1, 1, 1))
    (3): ELU(alpha=1.0)
    (4): Conv3d(33, 34, kernel_size=(5, 5, 5), stride=(1, 1, 1))
    (5): ELU(alpha=1.0)
    (6): Conv3d(34, 35, kernel_size=(2, 3, 4), stride=(1, 1, 1))
    (7): ELU(alpha=1.0)
    (8): SquashDims()
)
forward(inputs: Tensor) Tensor[source]

定義每次呼叫時執行的計算。

應由所有子類別覆寫。

注意

雖然 forward pass 的配方需要在這個函數中定義,但是應該在此之後呼叫 Module 實例,而不是呼叫這個函數,因為前者會處理執行的已註冊 hooks,而後者會靜默地忽略它們。

文件

存取 PyTorch 的完整開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並取得問題解答

檢視資源